【问题标题】:Matplotlib Italic in portion of axes labels - applied to default font but not specified font轴标签部分中的 Matplotlib 斜体 - 应用于默认字体但未指定字体
【发布时间】:2020-04-14 05:43:31
【问题描述】:

我希望情节中的所有文本都是 Times New Roman,所以我做了以下操作:

import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman" # change default font

我只希望标签的“(x)”和“(z)”部分是斜体,所以我这样做了:

plt.xlabel('Underutilization $\it{(x)}$', labelpad=15)
plt.ylabel('Productivity $\it{(z)}$', labelpad=15)

但是,我在绘图时最终得到的是 Times New Roman 中的“Underutilization”,而斜体无衬线字体(Python 的默认值)中的“(x)”。与 ylabel 相同。

我该如何补救?

【问题讨论】:

    标签: python matplotlib fonts label italic


    【解决方案1】:

    $ 符号内的文本由 matplotlib 的 mathtext 指示(除非您使用 LaTex),并由 rcParam mathtext.fontset 控制,documentation 中概述了

    mathtext.fontset: ‘dejavusans’(默认)
    ‘dejavuserif’, ‘cm’ (Computer Modern), ‘stix’,
    “stixsans”或“custom”

    使用LaTex for the text rendering 提供了更大的字体选择灵活性,我相信会支持Times New Roman。如果您使用 LaTex,那么它应该在您调整 font.family 时调整数学字体。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-03
      • 1970-01-01
      • 2016-08-10
      相关资源
      最近更新 更多