A.A*_*age 3 python fonts matplotlib python-3.x
所以我已经尝试了几乎所有我能在 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()
Run Code Online (Sandbox Code Playgroud)
给我这个错误日志:
>>> (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]))
>>>
Run Code Online (Sandbox Code Playgroud)
这个答案也没有帮助我:
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()
Run Code Online (Sandbox Code Playgroud)
没有显示错误;但这不是时代...

对我来说,第一次尝试给出错误日志也有点奇怪,因为按照这个答案的建议进行操作表明 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'}
Run Code Online (Sandbox Code Playgroud)
所以......我还能尝试什么?
为了查看哪些字体可用,您应该使用此方法:
import matplotlib.font_manager
flist = matplotlib.font_manager.get_fontconfig_fonts()
names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
print names
Run Code Online (Sandbox Code Playgroud)
然后看看有没有“Times New Roman”。
if "Times New Roman" in names:
print "Yes"
else:
print "font not available"
Run Code Online (Sandbox Code Playgroud)
如果不是,您将无法使用它。如果是,以下将按预期工作。
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman"
plt.plot([1,2,3])
plt.title('Please be Times New Roman')
plt.show()
Run Code Online (Sandbox Code Playgroud)
请注意,您可以指定多种字体。将选择实际可用的第一个。"serif"如果不存在其他字体,则在列表中添加最后一个至少可以确保回退到衬线字体。
plt.rcParams["font.family"] = "Gulasch", "Times", "Times New Roman", "serif"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12916 次 |
| 最近记录: |