Sans-serif math with latex in matplotlib

前端 未结 3 885
暖寄归人
暖寄归人 2020-11-29 06:16

The following script:

import matplotlib
matplotlib.use(\'Agg\')
import matplotlib.pyplot as mpl

mpl.rc(\'font\', family=\'sans-serif\')
mpl.rc(\'text\', use         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 06:44

    I always have text.usetex = True in my matplotlibrc file. In addition to that, I use this as well:

    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!
    ]  
    

    Hope that helps.

提交回复
热议问题