gpt4 book ai didi

python - Matplotlib 中轴上的数字和轴标签具有相同的字体

转载 作者:行者123 更新时间:2023-12-01 09:24:44 26 4
gpt4 key购买 nike

我有以下代码来创建如下所示的绘图:

import matplotlib.pyplot as plt

x = [...]
y = [...]
fig = plt.figure()
ax = fig.gca()
ax.set_xlabel(r'$\mathsf{Concentration [mol/m^{3}]}$')
ax.set_ylabel(r'$\mathsf{Diffusion Coefficient [m^2/s]}$')
plt.semilogy(x, y)
plt.grid(True, which="both")
plt.autoscale()
plt.savefig("coeff.pdf")
plt.show()

完全可以使用 LaTeX 数学符号作为轴标签。不幸的是,刻度线/网格线处的数字有另一种字体:

Plot with two different fonts

如何确保轴标签和数字具有相同的字体和样式?

最佳答案

您需要将mathtext字体设置为常规字体:

from matplotlib import rcParams
rcParams['mathtext.default'] = 'regular'

这适用于使用 mathtext 进行方程渲染。如果你使用 Latex,你应该看看 here .

关于python - Matplotlib 中轴上的数字和轴标签具有相同的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50526864/

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