美文网首页
Ubuntu平台上用matplotlib的xkcd模式画图出现找

Ubuntu平台上用matplotlib的xkcd模式画图出现找

作者: 穆弋 | 来源:发表于2016-01-27 14:26 被阅读586次

    在Ubuntu平台上使用matplotlib的xkcd模式画图时,会出现
    /usr/local/lib/python3.4/dist-packages/matplotlib/font_manager.py:1288: UserWarning: findfont: Font family ['Humor Sans', 'Comic Sans MS'] not found. Falling back to Bitstream Vera Sans (prop.get_family(), self.defaultFamily[fontext]))错误,虽然最后也能成功地生成图片,但是字体用的是系统的默认字体,而不是xkcd风格的字体,下面我给出解决方法。

    使用的是我的电脑的路径,你们需要根据自己的电脑修改路径。
    首先安装comic sans ms字体
    sudo cp <字体文件> /usr/share/fonts/truetype/comic/
    fc-cache -r
    删除matplotlib在~/.cache文件夹中创建的临时文件
    rm -rf ~/.cache/matplotlib

    尝试画图,如果成果则是成功了,如果不成功那就直接把字体复制到matplotlib的库中。
    cp <字体文件> /usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts
    rm -rf ~/.cache/matplotlib
    看看效果。

    figure_1-1.png figure_1.png

    相关文章

      网友评论

          本文标题:Ubuntu平台上用matplotlib的xkcd模式画图出现找

          本文链接:https://www.haomeiwen.com/subject/hsgdkttx.html