Matplotlib, Consistent font using latex

后端 未结 2 1135
后悔当初
后悔当初 2020-12-02 07:50

My problem is I\'d like to use Latex titles in some plots, and no latex in others. Right now, matplotlib has two different default fonts for Latex titles and non-Latex titl

2条回答
  •  执笔经年
    2020-12-02 08:36

    EDIT

    if you want to change the fonts used by LaTeX inside matplotlib, check out this page

    http://matplotlib.sourceforge.net/users/usetex.html

    one of the examples there is

    from matplotlib import rc
    rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
    ## for Palatino and other serif fonts use:
    #rc('font',**{'family':'serif','serif':['Palatino']})
    rc('text', usetex=True)
    

    Just pick your favorite!

    And if you want a bold font, you can try \mathbf

    plt.title(r'$\mathbf{W_y(\tau, j=3)}$')
    

    EDIT 2

    The following will make bold font default for you

    font = {'family' : 'monospace',
            'weight' : 'bold',
            'size'   : 22}
    
    rc('font', **font)
    

提交回复
热议问题