python 作图中设置标签将‘Hm0’中‘m0’变为下标特殊符号的字体也保持为Times New Roman
可以使用matplotlib库中的text函数来设置标签,并使用LaTeX语法设置下标和字体。具体代码如下:
import matplotlib.pyplot as plt
import matplotlib as mpl
# 设置特殊符号的字体为Times New Roman
mpl.rcParams['mathtext.fontset'] = 'stix'
mpl.rcParams['font.family'] = 'Times New Roman'
# 设置数据
Hm0 = [1, 2, 3, 4, 5]
T = [5, 6, 7, 8, 9]
# 绘制图形
plt.plot(T, Hm0)
# 设置标签
plt.xlabel('T')
plt.ylabel(r'$H_{m0}$')
# 显示图形
plt.show()
运行后,可以看到x轴和y轴的标签分别为'T'和'Hm0',其中'Hm0'的'm0'已经变为下标,并且特殊符号的字体为Times New Roman。
原文地址: https://www.cveoy.top/t/topic/bf9L 著作权归作者所有。请勿转载和采集!