引言
做科研的同学肯定都经历过这样的时刻:辛辛苦苦跑完实验,用 Python 画出了精美的折线图,结果投稿时被审稿人一句冷冰冰的意见打回:
'Figures should use standard fonts (e.g., Times New Roman). The current font looks like Arial/Computer Modern.'
你可能会疑惑:我明明在 PPT 里看是 Times New Roman 啊?为什么 Matplotlib 默认画出来的公式(尤其是这种变量)看起来就是'不对味'?
本文将带你通过三个层级,彻底解决 Matplotlib 中的 Times New Roman 字体问题,并顺带解密那个让无数人困惑的字母 'Q'。
基础方案:STIX 字体(最快上手)
Matplotlib 自带了一套名为 STIX (Scientific and Technical Information Exchange) 的字体,它是专门为了模仿 Times New Roman 而设计的。
适用场景: 一般会议论文,或者对字体细节要求不严苛的场合。
代码实现:
import matplotlib.pyplot as plt
# 将数学公式字体设置为 stix
plt.rcParams['mathtext.fontset'] = 'stix'
# 将普通文本字体设置为衬线字体
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.serif'] = ['Times New Roman']
plt.plot([1, 2, 3])
plt.title(r"Result: $Q_i = \sin(x)$")
plt.show()
缺点: STIX 毕竟只是'模仿者'。在某些字母的细节上(例如数字 1 的起笔、v 的弯曲度),它和真正的 Times New Roman 还是有肉眼可见的区别。
进阶方案:强制调用系统字体(无需安装 LaTeX)
如果你有'强迫症',或者期刊要求必须使用操作系统自带的 Times New Roman,可以使用 Custom(自定义)模式。这招能骗过 99% 的审稿人。
适用场景: 绝大多数 SCI 期刊,不想折腾 LaTeX 环境的 Windows/Mac 用户。
代码实现:
config = {
"font.family": 'serif',
"font.serif": ['Times New Roman'],
"mathtext.fontset": 'custom',
"mathtext.rm": 'Times New Roman',
"mathtext.it": ,
:
}
plt.rcParams.update(config)

