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

Python 如何在matplotlib/seaborn上设置带有LaTex符号的轴标签的字体大小?,python,matplotlib,seaborn,Python,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

在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。缓解“普通”字体和“乳胶”字体之间差异的一种方法是使用\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()

我认为你不能仅仅增加字母alpha:你可以增加整个标签,但这不是你想要的。考虑从标题中删除alpha并将其添加到您喜欢的大小的单独文本字段中:<代码> PLT.Text(0.5,-0.1,R'$Alpha $,ftOntSt= 40)< /Cl> >我从来没有理解为什么胶乳字体比MatPlTLIB中的普通字体小,但是您可以将整个标签写入胶乳中,例如“代码> R'$Alph\/Mathsf{(距离\/加权)}。$”。