当我尝试使用 matplotlib 绘制图形时,我用文本和“数学文本”编写了 x 轴标签。因为我要在标签上写化学式,所以写成“$CO_2$浓度”。问题是我希望字体应该是 times new roman,但我无法以某种方式更改美元符号中的字体。有人可以帮我解决吗?非常感谢!
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
xf1 = pd.read_excel('1812_GPT.xlsx',sheetname= 'PVD_CO2CH4_600',usecols=[1])
deltapx1 = pd.read_excel('1812_GPT.xlsx',sheetname= 'PVD_CO2CH4_600',usecols=[3])
Px1 = pd.read_excel('1812_GPT.xlsx',sheetname= 'PVD_CO2CH4_600',usecols=[5])
ax1 = plt.subplot(111)
l1, = ax1.plot(xf1,Px1,'s',markerfacecolor='black')
font1 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size' : 14,
}
ax1.set_xlabel(r'$CO_2$ pressure', font1)
ax1.set_ylabel(r'$CO_2$ concentration', font1)
plt.show()
Run Code Online (Sandbox Code Playgroud)
这是图片链接,你可能看到图片后发现Times new roman中没有“CO2”。 https://flic.kr/p/2dmh8pj