如何在matplotlib/seaborn中使用LaTex符号设置轴标签的字体大小?

5
在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()

但我得到了以下的图表:

enter image description here

请注意,$\alpha$ 仍然很小。


我认为你不能仅仅增加字母α的大小:你可以增加整个标签的大小,但这不是你想要的。考虑从标题中删除α,并在单独的文本字段中添加所需大小的α:<code>plt.text(0.5,-0.1,r'$\alpha$', fontsize=40)</code> - selyunin
我从来不明白为什么在matplotlib中,LaTeX字体要比普通字体小,但你可以用LaTeX写整个标签,例如 r'$\alpha\/\mathsf{(distance\/weighted)}$' - mwaskom
1个回答

3

要增加字体的大小,请将所需值设置为fontsize。缓解“正常”字体和“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()

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接