Getting xkcd graphs using matplotlib

The current version of matplotlib (1.3.1) supports hkcd style building, but when I follow the basic instructions for creating such a graph (in iPython 1.1.0),

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

I get

enter image description here

instead

enter image description here

What am I doing wrong?

+11
source share
3 answers

To make it work you need

  • matplotlib 1.3.1 (it will not work with matplotlib 1.3.0 or earlier)
    • sudo pip install matplotlib --upgrade
  • Humor Sens font
    • download from here or here , install (in OS X you will 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 the backend to TkAgg , as some people suggest. For me, it works great on 'module://IPython.kernel.zmq.pylab.backend_inline' (you can check it on plt.get_backend() ).

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

+12
source

From the blog post you linked :

In addition, if you want the font to match the above, be sure to download and install the Humor Sans font on your system. In order for matplotlib to recognize it, you may need to delete the font cache ...

As for which version of the font to download, I would try the latest one.

0
source

Using ubuntu 16.04 and python 3, with matplotlib 2.0.0 the following works for me.

  • Install Comic sans: sudo apt install fonts-humor-sans
  • Delete matplotlib cache: rm ~/.cache/matplotlib -r
0
source

Source: https://habr.com/ru/post/1203825/


All Articles