我试图用matplotlib(ver。1.4.2)在Python 3下。
当我试图逃跑时:
import matplotlib.pyplot as plt
plt.xkcd()
plt.plot([1,2,3,4], [1,4,9,16], 'bo')
plt.axis([0, 6, 0, 20])
plt.show()
它打开一个没有任何图像的空窗口,我得到错误:
/usr/lib/python3/dist-packages/matplotlib/font_manager.py:1279: UserWarning: findfont: Font family ['Humor Sans', 'Comic Sans MS', 'StayPuft'] not found. Falling back to Bitstream Vera Sans
(prop.get_family(), self.defaultFamily[fontext]))
/usr/lib/python3/dist-packages/matplotlib/font_manager.py:1289: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=medium. Returning /usr/share/matplotlib/mpl-data/fonts/ttf/STIXSizOneSymReg.ttf
UserWarning) Exception in Tkinter callback
我安装了幽默Sans。我用fc-list | grep Humor
查过了。它也可以在其他程序中使用,如Libre Office。我也安装了staypuft。这还不够吗?
上面相同的代码,但没有plt.xkcd()位,工作正常。
plt.show()的另一种替代方法,如pylab.savefig()对于xkcd代码也不起作用,但是如果不使用xkcd,相同的代码也不会有任何问题。
如果在安装matplotlib后添加新字体,则尝试删除
~/.matplotlib/fontList.cache
,matplotlib必须重新生成字体。更新
如注释中的Pierre B所述,matplotlib字体缓存可能位于
~/.cache/matplotlib/fontList.json
下。删除该文件可以解决问题。对于Mac用户:尝试在python中运行此命令:(或在.py文件之前)
相关问题 更多 >
编程相关推荐