我尝试了几乎所有在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字体...
对我来说,第一次尝试会出现那个错误日志有点奇怪,因为按照 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'}
那么...我还能尝试什么?
'Times'
而不是'Times New Roman'
作为字体名称。 - jdehesa