内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
以下脚本:
import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as mpl mpl.rc('font', family='sans-serif') mpl.rc('text', usetex=True) fig = mpl.figure() ax = fig.add_subplot(1,1,1) ax.text(0.2,0.5,r"Math font: $451^\circ$") ax.text(0.2,0.7,r"Normal font (except for degree symbol): 451$^\circ$") fig.savefig('test.png')
有没有办法把数学字体也设为无衬线字体?
我一直text.usetex = True
。除此之外,我还使用了以下内容:
mpl.rcParams['text.latex.preamble'] = [ r'\usepackage{siunitx}', # i need upright \micro symbols, but you need... r'\sisetup{detect-all}', # ...this to force siunitx to actually use your fonts r'\usepackage{helvet}', # set the normal font here r'\usepackage{sansmath}', # load up the sansmath so that math -> helvet r'\sansmath' # <- tricky! -- gotta actually tell tex to use! ]