所以我已经尝试了几乎所有我能在 stackoverflow 上找到的东西(以及谷歌会引导我的任何其他地方);我只是不能改变该死的字体!
这是我迄今为止尝试过的非详尽列表:
按照 这个问题 的建议尝试:
import matplotlib.pyplot as plt
csfont = {'fontname':'Times New Roman'}
x = [1,2,3]
y = x
plt.plot(x,y)
plt.title('Please be Times >__<',**csfont)
plt.show()
给我这个错误日志:
>>> (executing file "<tmp 1>")
Note on using QApplication.exec_():
The GUI event loop is already running in the pyzo kernel, and exec_()
does not block. In most cases your app should run fine without the need
for modifications. For clarity, this is what the pyzo kernel does:
- Prevent deletion of objects in the local scope of functions leading to exec_()
- Prevent system exit right after the exec_() call
/home/antoine/miniconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))
>>>
这个答案 对我也没有太大帮助:
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman"
x = [1,2,3]
y = x
plt.plot(x,y)
plt.title('Please be Times >__<',**csfont)
plt.show()
没有显示错误;但这不是时代…
第一次尝试给出错误日志对我来说也有点奇怪,因为按照 这个答案 的建议表明 Times New Roman 确实是我应该能够使用的字体:
>>> set([f.name for f in matplotlib.font_manager.fontManager.afmlist])
{'Courier', 'Times', 'URW Bookman L', 'Nimbus Mono L', 'ITC Bookman', 'ZapfDingbats', 'Century Schoolbook L', 'New Century Schoolbook', 'Helvetica', 'Standard Symbols L', 'Utopia', 'Palatino', 'URW Gothic L', 'Courier 10 Pitch', 'Symbol', 'Computer Modern', 'Bitstream Charter', 'ITC Avant Garde Gothic', 'Nimbus Roman No9 L', 'ITC Zapf Chancery', 'ITC Zapf Dingbats', 'URW Chancery L', 'Nimbus Sans L', 'Dingbats', 'URW Palladio L'}
那么…我还能尝试什么?
原文由 A.Aussage 发布,翻译遵循 CC BY-SA 4.0 许可协议
为了查看哪些字体可用,您应该使用 此方法:
然后看看有没有“Times New Roman”。
如果不是,则不能使用它。如果是,以下将按预期工作。
请注意,您可以指定多种字体。将选择实际可用的第一个。在列表的最后添加
"serif"
至少确保在没有其他字体存在的情况下退回到衬线字体。