π 2013-Oct-09 ⬩ βοΈ Ashwin Nanjappa ⬩ π·οΈ matplotlib, plot, python, xkcd ⬩ π Archive
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 distribute
.
pip
to 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.
XKCD plots use a font named Humor Sans. Download it from here. To install it follow the steps described here.
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