当我试图用matplotlib绘制一个图形时,我用文本和“数学文本”编写了x轴标签。因为我要在标签上写一个化学式,写的是“$CO_2$concentration”。问题是,我希望字体应该是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()
这是图片链接,你可以看到图片,发现“二氧化碳”不是在新罗马时代。 https://flic.kr/p/2dmh8pj
我发现最好一次定义整个字体系列,而不是单独定义(假设您想要相同的字体)。试试这个
我不认为将任何mathtext更改为任意字体是不容易的。但是,如果
"CO_2"
只包含常规符号,则可以使用\mathdefault{}
使mathtext使用常规字体中的符号。在类似},这两个元素当然存在于Times New Roman中)。在
r"$\mathdefault{\sum_\alpha^\beta\frac{i}{9}}$
的内容仍将在通常的默认数学字体集中呈现(除了"i"
和{对于一般情况,您还可以将完整的数学字体集更改为
^{pr2}$cm
,stix
,stixsans
,dejavuserif
,dejavusans
。最接近“新罗马时代”的是stix
。在一般建议阅读MathText tutorial。在
相关问题 更多 >
编程相关推荐