Matplotlib轴标签中的斜体-应用于默认字体,但未指定字体

问题描述 投票:1回答:1

我希望我的地块中的所有文字都是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中的'Unutiltilization',而在斜体的sans serif(Python的默认值)中是'(x)'。与ylabel相同。

我该如何补救?

python matplotlib fonts label italic
1个回答
0
投票

$符号内的文本由matplotlib的mathtext(除非您使用的是LaTex)决定,并由rcParam mathtext.fontset控制,documentation中用[]概述了这些内容>]

mathtext.fontset:“ dejavusans”(默认)“ dejavuserif”,“ cm”(现代计算机),“ stix”,“ stixsans”或“ custom”

© www.soinside.com 2019 - 2024. All rights reserved.