【问题标题】:matplotlib - set font to Times New Romanmatplotlib - 将字体设置为 Times New Roman
【发布时间】:2022-01-23 04:44:08
【问题描述】:

我想在我的 matplotlib 绘图中使用 Times New Roman 字体。我目前正在使用matplotlib-3.5.1,并且我安装了fonttools-4.28.5。但是,当我尝试时:

plt.rcParams["font.family"] = "Times New Roman"

字体不变。然后我找到了一个建议来尝试:

plt.rcParams["font.family"] = "DejaVu Serif"
plt.rcParams["font.serif"] = ["Times New Roman"]

这也没有效果。我做错了什么,我该如何解决?

我已经看过其他帖子,例如1, 2 无济于事。

编辑:在this post 之后,matplotlib 似乎没有 Times New Roman?

['C059', 'C059', 'C059', 'C059', 'D050000L', 'DejaVu LGC Sans Mono', 'DejaVu LGC Sans Mono', 'DejaVu LGC Sans Mono', 'DejaVu LGC Sans Mono', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans', 'DejaVu Sans Display', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Sans Mono', 'DejaVu Serif', 'DejaVu Serif', 'DejaVu Serif', 'DejaVu Serif', 'DejaVu Serif Display', 'Liberation Mono', 'Liberation Mono', 'Liberation Mono', 'Liberation Mono', 'Nimbus Mono PS', 'Nimbus Mono PS', 'Nimbus Mono PS', 'Nimbus Mono PS', 'Nimbus Roman', 'Nimbus Roman', 'Nimbus Roman', 'Nimbus Roman', 'Nimbus Sans', 'Nimbus Sans', 'Nimbus Sans', 'Nimbus Sans', 'Nimbus Sans Narrow', 'Nimbus Sans Narrow', 'Nimbus Sans Narrow', 'Nimbus Sans Narrow', 'P052', 'P052', 'P052', 'P052', 'STIX', 'STIX', 'STIX', 'STIX', 'STIX Math', 'STIXGeneral', 'STIXGeneral', 'STIXGeneral', 'STIXGeneral', 'STIXNonUnicode', 'STIXNonUnicode', 'STIXNonUnicode', 'STIXNonUnicode', 'STIXSizeFiveSym', 'STIXSizeFourSym', 'STIXSizeFourSym', 'STIXSizeOneSym', 'STIXSizeOneSym', 'STIXSizeThreeSym', 'STIXSizeThreeSym', 'STIXSizeTwoSym', 'STIXSizeTwoSym', 'URW Bookman', 'URW Bookman', 'URW Bookman', 'URW Bookman', 'URW Gothic', 'URW Gothic', 'URW Gothic', 'URW Gothic', 'Z003', 'cmb10', 'cmex10', 'cmmi10', 'cmr10', 'cmss10', 'cmsy10', 'cmtt10']

【问题讨论】:

    标签: matplotlib


    【解决方案1】:

    按照https://matplotlib.org/stable/gallery/text_labels_and_annotations/font_family_rc_sgskip.html?highlight=font#configuring-the-font-family,这应该可以工作:

    plt.rcParams["font.family"] = "serif"
    plt.rcParams["font.serif"] = ["Times New Roman"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      • 2011-05-27
      • 2018-10-24
      • 1970-01-01
      相关资源
      最近更新 更多