【发布时间】:2018-02-03 06:55:12
【问题描述】:
所以我已经尝试了几乎所有我可以在 stackoverflow 上找到的东西(以及谷歌会引导我的任何其他地方);我就是不能改变该死的字体!
这是我迄今为止尝试过的非详尽列表:
按照this question 中的建议尝试:
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]))
>>>
This answer 也没有帮到我:
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()
没有显示错误;但这不是时代……
第一次尝试给出错误日志对我来说也有点奇怪,因为按照this answer 的建议进行操作表明 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'}
那么...我还能尝试什么?
【问题讨论】:
-
你试过其他字体吗?无论如何,您最后的 sn-p 似乎表明您应该使用的字体名称可能是
'Times'而不是'Times New Roman'。 -
我都试过了,即使是'Times-Roman',它仍然没有工作..
标签: python python-3.x matplotlib fonts