Home > database >  Cannot label math symbol in regular font and italic style
Cannot label math symbol in regular font and italic style

Time:11-26

Referring to this question thread STIX label

Note that the ticks on the x-axis and y-axis still use the default font (DejaVu Sans). If you want to use Times New Roman for everything, just set the font.family parameter.

import matplotlib.pyplot as plt
plt.rcParams['mathtext.fontset'] = 'stix'
plt.rcParams['font.family'] = 'STIXGeneral'
plt.xlabel(r'Displacement ($\mathrm{\AA}$) ($\AA$)', fontsize=12)
plt.show()

STIX everywhere

Tested on Python 3.8.10 and 3.10.8.

CodePudding user response:

It didn't work. I mean I can get this result when I'm using older python version with

plt.xlabel(r'Displacement ($\AA$), fontname="STIXGeneral'))

but when I use the latest version, with this command, I can't obtained this output. I download Anaconda and work on a new Windows computer, which I run the python script from Anaconda Powershell Prompt, not sure will this have any effect?

Here is the more detailed script with other package import:

import pandas as pd
import glob
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import sys
from scipy import integrate
from tqdm import tqdm
import os

Plot the data

plt.axis([None, None, None, None])
plt.rcParams['mathtext.fontset'] = 'stix'

plt.legend(fontsize=7)

plt.xlabel(r'Displacement ($\AA$)',fontname="STIXGeneral",fontsize=12)
plt.ylabel("Stress (GPa)",fontname="STIXGeneral",fontsize=12)
plt.grid(color ='black', linestyle ='dotted', linewidth = 0.5, dashes=(3, 
5),alpha=0.4)               #alpha is the transparency of the grid
plt.savefig(fig_name,format='svg', dpi=1200)

Still the same

Same

  • Related