我正在尝试在Python 3下使用matplotlib(版本1.4.2)绘制类似xkcd的图形。
当我运行以下命令时:
当我运行以下命令时:
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
我已经安装了Humor Sans字体,并用fc-list | grep Humor
检查了它。它也可以在其他程序中使用,比如Libre Office。我还安装了staypuft。这不够吗?
相同的代码,但没有plt.xkcd()部分,可以完美地工作。
plt.show()的替代方法,如pylab.savefig()也无法与xkcd代码一起使用,但不会对不使用xkcd的相同代码造成任何问题。
import matplotlib as mpl; print(mpl.get_cachedir())
来查找缓存目录的路径。 - steven