Python matplotlib subscript font setting problem

created at 07-29-2021 views: 23


subscript font

The python code used (first step in your own python):

df_up= pd.read_excel(xlsxFilename)

This mathrm is the first step to make the subscript into the desired font

available fonts

If you don’t understand, you can copy the above code directly to your document.

global font settings

At this point, you will find that even after using the above, the picture that comes out still looks unsatisfactory, because it is just like the picture below

global font settings

If I want the above "sou" to also become "Times New Roman" font, what should I do?

plt.rcParams['mathtext.fontset'] = 'stix'# Most similar to Times new roman

Or (I didn't use this, but you can try)

import matplotlib.pyplot as plt
from matplotlib import rcParams
config = {
    "font.size": 20,
    "font.serif": ['SimSun'],


plt.rcParams[''] = "Times New Roman"
plt.rcParams["mathtext.fontset"] = "dejavuserif"
plt.rc('text', usetex=True )


If you show up at this step:

RuntimeError: Failed to process string with tex because latex could not be found

you can

first step:

pip install latex

second step:
The main reason for this problem is the lack of latex, dvipng and ghostscript 
Just choose one of the 3 subordinates (anaconda)

conda install -c conda-forge jupyter_latex_envs
conda install -c conda-forge/label/cf201901 jupyter_latex_envs
conda install -c conda-forge/label/cf202003 jupyter_latex_envs

third step
After the above attempts, it doesn’t work, what should I do, download Protext and only install miktex

 install miktex

fourth step


test latex

created at:07-29-2021
edited at: 07-29-2021: