如何在 matplotlib/seaborn 上设置带有 LaTex 符号的轴标签的字体大小?

How to set fontsize of axis label with LaTex symbol on matplotlib/seaborn?

在 matplotlib 中,如何更改 Latex 符号的字体大小?

我有以下代码:

import matplotlib.pyplot as plt
import seaborn as sns

# get x and y from file

plt.plot(x, y,  linestyle='--', marker='o', color='b')
plt.xlabel(r'$\alpha$ (distance weighted)', fontsize='large')
plt.ylabel('AUC')
plt.show()

但我得到了下图:

注意 $\alpha$ 仍然很小。

要增加字体的大小,请将所需的值设置为 fontsize。减轻 "normal" 字体和 "latex" 字体之间差异的一种方法是使用 \mathrm。下面的示例显示了这样做的行为:

import matplotlib.pyplot as plt
import seaborn as sns

x = np.arange(10)
y = np.random.rand(10)

fig = plt.figure(1, figsize=(10,10))

for i, j in zip(np.arange(4), [10,15,20,30]):
    ax = fig.add_subplot(2,2,i+1)
    ax.plot(x, y,  linestyle='--', marker='o', color='b')
    ax.set_xlabel(r'$\mathrm{\alpha \ (distance \ weighted)}$', fontsize=j)
    ax.set_ylabel('AUC')
plt.show()