如何在 Matplotlib 中组合普通字体和 Latex 字体类型?

问题描述 投票:0回答:1

我知道 Matplotlib 的

math_fontfamily
可以在同一字符串中混合系列字体类型。我在我的标题中使用了该功能,并且效果非常好。例如:

ax[0].set_title(r'Total response $\tau_c/\tau$', math_fontfamily='cm')

混合普通文本和乳胶文本。

现在,我想对情节图例使用相同的功能。我正在使用“标签”命令,如

ax[0].plot(x, y, label="I want normal text and latex text, eg $\tau/\gamma$")
ax[0].legend(loc='lower center')

我该怎么做?

python legend font-family
1个回答
0
投票

一种可能的选择是通过 Matplotlib 的 rcParams 启用 Latex 渲染,例如:

plt.rcParams.update({
    "text.usetex": True,
    "font.family": "Helvetica"
})

请参阅文档了解更多信息。请注意,这需要安装有效的 Latex。

© www.soinside.com 2019 - 2024. All rights reserved.