When I tried to polt a figure with matplotlib, I wrote the x axis label with both text and "math text". Because I have to write a chemical formula in the label, it was written as '$CO_2$ concentration'. The question is that I hope the font should be times new roman, but I cannot change the font in the dollar sign somehow. Is there anyone who can help me fix it? Thank you very much!
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()
This is the picture link, you may see the pic and find that "CO2" is not in Times new roman. https://flic.kr/p/2dmh8pj