Matplotlib can't find font

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

I am trying to draw an xkcd-style plot with matplotlib (ver. 1.4.2) under Python 3.

When I try to run:

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() 

It opens an empty window without any image and I get the error:

/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 

I have Humor Sans installed. I checked it with fc-list | grep Humor. It can also be used within other programs, like Libre Office. I also have staypuft installed. Isn't that enough?

The same code above but without the plt.xkcd() bit works flawlessly.

An alternative to plt.show(), like pylab.savefig() won't work either for the xkcd code, but doesn't have any problem with the same code without using xkcd.

回答1:

If your add a new font after installing matplotlib then try to remove ~/.matplotlib/fontList.cache and matplotlib have to rebuild fonts.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!