下标不是使用matplotlib的times new roman格式

2024-09-29 00:11:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用matplotlib打印和times new roman字体。然而,在最新版本中,下标不是在Times New Roman中,而其他文本是在Times New Roman中。外观如下。在

figure1

例如,代码是as

import matplotlib as mlp,numpy as np
mlp.rc('font',family='Times New Roman')
import matplotlib.pyplot as plt
fig = plt.figure();
plt.xlabel('N$_{sou}$=20',fontsize=20)
plt.show()

这个数字是 figure2

下标“sou”不在Times New Roman中,而“N”在Times New Roman中。在

如何解决这个问题?在


Tags: 文本import版本newmatplotlibas字体plt
1条回答
网友
1楼 · 发布于 2024-09-29 00:11:42

在TeX数学模式下,使用专用的数学字体(通常是您使用的字体的斜体版本)显示数学表达式是标准的。Matplotlib似乎模仿了这种行为。在TeX(或LaTeX)中,可以通过使用mathrm命令来恢复旧字体,该命令在matplotlib中似乎也可以工作,如下所示:

import matplotlib as mlp,numpy as np
mlp.rc('font',family='Times New Roman')
import matplotlib.pyplot as plt
fig,axes = plt.subplots(1,2);
axes[0].set_xlabel('N$_{sou}$=20',fontsize=20)
axes[0].set_title('normal math mode')
axes[1].set_xlabel('N$_\mathrm{sou}$=20', fontsize=20)
axes[1].set_title('using \mathrm')
plt.show()

result of above code

相关问题 更多 >