代码之家  ›  专栏  ›  技术社区  ›  outlaw

升级后的python matplotlib更改了latex字体

  •  3
  • outlaw  · 技术社区  · 6 年前

    在升级matplotlib库(macOS)之前,我的图形文本中有以下latex字体: enter image description here

    然而,更新后,我得到了以下字体: enter image description here

    在这两种代码中,我都使用以下命令: plt.title(r'$L_x = 1\mathrm{m}, \ \phi_{in}=1$') 。 你能帮我把第一个数字的字体拿回来吗?

    非常感谢

    2 回复  |  直到 6 年前
        1
  •  3
  •   ImportanceOfBeingErnest    6 年前

    MathText 有自己的字体集。您可以通过 rcParam mathtext.fontset

    #mathtext.fontset : dejavusans ## Should be 'dejavusans' (default),
                                   ## 'dejavuserif', 'cm' (Computer Modern), 'stix',
                                   ## 'stixsans' or 'custom'
    

    要获取衬线MathText,请使用, dejavuserif ,则, cm stix

    实例

    plt.rcParams["mathtext.fontset"] = "stix"
    
        2
  •  1
  •   Christian    6 年前

    在绘图前添加以下行

    from matplotlib import rc
    rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
    rc('text', usetex=True)
    

    你可能需要挖掘一些来找到正确的字体,也许你原来的字体不是“sans-serif”。