我正在Canopy中使用matplotlib库,具体的函数是xkcd()。这个函数使用特定的字体绘制图表。该字体为Comic Sans MS,如果没有安装,则需要下载。
/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/font_manager.py:1236: UserWarning: findfont: Font family ['Humor Sans', 'Comic Sans MS'] not found. Falling back to Bitstream Vera Sans (prop.get_family(), self.defaultFamily[fontext]))
我使用下面的小脚本,检查字体的存在/缺失情况。如果不存在,则下载它。import os
import urllib2
if not os.path.exists('Humor-Sans.ttf'):
fhandle = urllib2.urlopen('http://antiyawn.com/uploads/Humor-Sans-1.0.ttf')
open('Humor-Sans.ttf', 'wb').write(fhandle.read())
问题在于我仍然无法正确显示所需字体。如果字体缓存出现问题,我会执行以下操作:
luis@luis-VirtualBox:~$ rm /home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/fontList.cache
获得以下内容:
rm: cannot remove ‘/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/fontList.cache’: No such file or directory
我错过了什么?
./.cache/matplotlib/fontList.cache
的地方,而不是安装路径中。你可能正在删除系统级别的fontList.cache
,它永远不会被重新生成。 - tacaswell