简体   繁体   English

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

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

In matplotlib, how can I change the font size of a latex symbol? 在matplotlib中,如何更改乳胶符号的字体大小?

I have the following code: 我有以下代码:

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

But I get the following graph: 但我得到以下图表:

在此输入图像描述

Notice that the $\\alpha$ is still small. 请注意,$ \\ alpha $仍然很小。

To increase the size of the fonts set the desired value to fontsize. 要增加字体的大小,请将所需的值设置为fontsize。 One way to mitigate the difference between the "normal" font and the "latex" one is by using \\mathrm. 减轻“普通”字体和“乳胶”字体之间差异的一种方法是使用\\ mathrm。 The example below shows the behaviour of doing this: 下面的示例显示了执行此操作的行为:

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

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM