[caption id="attachment_3898" align="aligncenter" width="576"](http://codeyarns.files.wordpress.com/2013/10/201310009-xkcd.png) Generate XKCD plot like this by adding a single function call[/caption]
Don't you think those plots, charts and graphs used in XKCD comic strips look really cool? I also think that by mimicking handwriting, these plots actually make the data more understandable. But, that's just me.
Matplotlib now includes support for XKCD plots! And it is really easy to use. If you are already using Matplotlib to generate plots for your data, then you can generate XKCD plots for those easily:
$ python >>> import matplotlib.pyplot >>> matplotlib.pyplot.xkcd() <matplotlib.rc_context object at 0x1ff9950>
If you see the above object being created then your Matplotlib supports XKCD plots. Jump to step 4. If you get a
AttributeError: 'module' object has no attribute 'xkcd' error, then you need to build the latest version of Matplotlib from source. See the next two steps.
$ sudo apt-get install tcl-dev tk-dev $ sudo pip install --upgrade distribute
I did these because building Matplotlib needs TCL and TK libraries for displaying plots and it needs a recent version of
pipto build and install the latest version for you:
$ sudo apt-get remove python-matplotlib $ sudo pip install matplotlib
Hopefully, that installation should work. If it fails during building then check what libraries its missing and install those packages.
You are ready to generate XKCD plots. Just add the call
matplotlib.pyplot.xkcd() before the other plotting calls in plot generating Python code. The generated plots will now be like in XKCD! :)
Tried with: Matplotlib 1.3.0 and Ubuntu 12.04 LTS