0

I'm not sure what the reason causing this, but when I apply this command line plt.rcParams['mathtext.fontset'] = 'stix' in labelling x-axis, it will not change the math symbol to font like Times New Roman. Did anyone how can I fix this?

import matplotlib.ticker as ticker
import matplotlib.pyplot as plt


plt.rcParams['mathtext.fontset'] = 'stix'        
plt.gca().xaxis.set_minor_locator(ticker.AutoMinorLocator())
plt.xlabel("COM Distance Between Polymer and Calcite Surface ($\AA$)",fontname="Times New Roman",fontsize=12)

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Huhu
  • 11
  • 2

1 Answers1

0

You can change font globably with plt.rcParams["font.family"] = "Times New Roman"

so

import matplotlib.ticker as ticker 
import matplotlib.pyplot as plt

plt.rcParams["font.family"] = "serif"
plt.rcParams["font.serif"] = ["Times New Roman"] + plt.rcParams["font.serif"]

plt.gca().xaxis.set_minor_locator(ticker.AutoMinorLocator()) 
plt.xlabel("COM Distance Between Polymer and Calcite Surface ($\mathdefault{\AA}$)",fontname="Times New Roman",fontsize=12)
35308
  • 575
  • 5
  • 17
  • I try this before but but I'm not sure why it only apply to Legend. For math symbol and x y label the font will not change... – Huhu Aug 22 '22 at 12:00
  • I see, well as https://stackoverflow.com/questions/53679650/how-to-change-font-in-which-is-in-math-form-in-python showed you can use `\mathdefault{}` but thats only for the special math symbols, i've updated my answer to show it. – 35308 Aug 23 '22 at 00:08