gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 16:26:03 25 4
gpt4 key购买 nike

在 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$ 仍然很小。

最佳答案

要增加字体的大小,请将所需的值设置为 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

关于python - 如何在 matplotlib/seaborn 上使用 LaTex 符号设置轴标签的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36519648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com