使用matplotlib获取xkcd图 [英] Getting xkcd plots using matplotlib
问题描述
matplotlib(1.3.1)的当前版本支持xkcd样式的绘图,但是当我解决方案
要使其正常运行,您需要
- matplotlib 1.3.1(不适用于matplotlib 1.3.0或更早版本)
-
sudo pip install matplotlib --upgrade
-
- font Humor Sans
- 从此处或
- 删除matplotlib字体缓存(如 DanHickstein在matplotlib/issues/2269 中所建议的那样)
-
rm ~/.matplotlib/fontList.cache
-
现在,执行代码,它应该可以工作.
您不需要,就像某些人建议的那样,将后端更改为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
- 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屋!