使用matplotlib获取xkcd图 [英] Getting xkcd plots using matplotlib

查看:131
本文介绍了使用matplotlib获取xkcd图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

matplotlib(1.3.1)的当前版本支持xkcd样式的绘图,但是当我解决方案

要使其正常运行,您需要

现在,执行代码,它应该可以工作.

不需要,就像某些人建议的那样,将后端更改为TkAgg.对我来说,它在'module://IPython.kernel.zmq.pylab.backend_inline'上可以正常工作(您可以通过plt.get_backend()进行检查).

(我遇到了同样的问题,并且至少在OS X 10.8.5上,使用matplotlib 1.3.1和IPython 2.0.0解决了该问题;删除字体缓存对于运行字体是必需的.)

The current version of matplotlib (1.3.1) supports xkcd-style plotting, but when I follow the basic instructions for generating such a plot (in iPython 1.1.0),

%pylab
plt.xkcd()
plt.plot(sin(linspace(0, 10)))
plt.title('Whoo Hoo!!!')

I get

instead of

What am I doing wrong?

解决方案

To get it working, you need

  • matplotlib 1.3.1 (it won't work with matplotlib 1.3.0 or earlier)
    • sudo pip install matplotlib --upgrade
  • font Humor Sans
    • download from here or here, install (on OS X you open it and click Install)
  • remove the matplotlib font cache (as suggested by DanHickstein in matplotlib/issues/2269)
    • rm ~/.matplotlib/fontList.cache

Now, execute the code and it should work.

You do not need to change backend to TkAgg, as some people suggest. For me it works perfectly fine on 'module://IPython.kernel.zmq.pylab.backend_inline' (you can check it by plt.get_backend()).

(I had the same problem and I've solved it, at least on OS X 10.8.5, with matplotlib 1.3.1 and IPython 2.0.0; removing font cache was necessary to get the font running.)

这篇关于使用matplotlib获取xkcd图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆