Matplotlib 2 inconsistent font

前端 未结 3 1065
情书的邮戳
情书的邮戳 2021-01-03 00:39

I updated Anaconda Python to the latest version (4.3), where they upgraded Matplotlib to version 2.

The upgrade has made some major changes to the default style (see

3条回答
  •  不知归路
    2021-01-03 01:11

    If consistency is the only issue, you can use a "Roman" style using the "Times" font. It is not necessary to use Latex via usetex. Instead simply use the STIX fontset, the Times font and serif mathtext.

    import scipy as sc
    import matplotlib.style
    import matplotlib.pyplot as plt
    
    params = {'legend.fontsize': 18,
              'axes.labelsize': 18,
              'axes.titlesize': 18,
              'xtick.labelsize' :12,
              'ytick.labelsize': 12,
              'grid.color': 'k',
              'grid.linestyle': ':',
              'grid.linewidth': 0.5,
              'mathtext.fontset' : 'stix',
              'mathtext.rm'      : 'serif',
              'font.family'      : 'serif',
              'font.serif'       : "Times New Roman", # or "Times"          
             }
    matplotlib.rcParams.update(params)
    
    x = sc.linspace(0,100)
    y = x**2
    fig = plt.figure('Fig')
    ax = fig.add_subplot(1, 1, 1)
    lines = ax.semilogy(x, y)
    
    ax.yaxis.set_minor_formatter(matplotlib.ticker.ScalarFormatter())
    ax.tick_params(axis='y', pad=10)
    ax.set_yticks([300], minor=True)
    ax.yaxis.grid(True, which='minor')
    ax.set_xlabel(r'$\mathrm{R_L}$')
    ax.set_ylabel(r'$\sigma \int_l \; dx$')
    plt.tight_layout()
    plt.show()
    

提交回复
热议问题