XKCD - The comic visuals !!

SANCHITA MANGALE
4 min readMay 8, 2021

--

We all know that an average person responds far better to visual information compared to just plain all text. Well first off, it could be something to do with the fact that 90% of information transmitted to the brain is visual, and visuals are processed in the brain at 60,000 times the speed of text. In other words, we look at pictures and videos regularly and we consume them more quickly than we do text.

Since we are visual by nature, we can use this skill to enhance data processing and organizational effectiveness. This is a very reason that Data Visualization is one most creative and important step in building solutions with Data Science.

We use many tools and libraries to plot the standard routine graphs and visualizing aids but humans tend to get bore with these. Hmm yes you can blame it on “hedonic adaptation” . boredom isn’t a character flaw. It’s a state brought on by a behavioral phenomenon called hedonic adaptation: the tendency for us to get used to things over time.

What if someone / something helps us make these standard visuals more exciting and in a more comic way ?
Here comes XKCD to our rescue.

Python provides us with an amazing Data Visualization library in it which is Matplotlib which was developed by John Hunter (1968–2012). Matplotlib is built on numpy and sideby framework that’s why it is fast and efficient. It is open source and have a huge community support. It possesses the ability to work well with many operating systems and graphic backends. Generally plots generated by Matplotlib are very perfect as well as monotonous. Observing these graphs are not that much fun. Matplotlib provides a library that can make these graphs a bit interesting and draws graphs in comic style. These graphs are interesting and everyone would love to study through these graphs.

What is xkcd?

xkcd is a webcomic created in 2005 by American author Randall Munroe. “A webcomic of romance, sarcasm, math, and language.” xkcd is an online Comic Strip that airs a new comic every week. It is one of the more popular comics. Most of them are related to math, computer programming or the internet.

Python interface with xkcd

This python library makes use of the JSON interface to Randall’s site to retrieve comic data. Both Python 2 and Python 3 are supported, and there are no dependencies beyond the Python standard library, so xkcd’s footprint should be very light.

There is support for accessing specific comics, the latest comic, or a random comic. Comic metadata can be queried and the comics themselves can be downloaded onto your local system. The goal is simply to provide a relatively Pythonic wrapper around the xkcd API for any Python program or library that wants to access information about xkcd comics, for one reason or another. The plt.xkcd() function enables some rcParam settings which can automatically convert any Matplotlib plot into XKCD style.

Take a look at this … how good are those two Sine functions with xkcd plot!!

Note : all the code snippets and images are from the same jupyter notebook hence xkcd is executed only one and not at all the places

By the way, this new functionality requires Matplotlib version 1.3, which can currently be downloaded and installed from GitHub. Also, if you want to have the font match above, be sure to download and install the Humor Sans font on your system. For Matplotlib to recognize it, you may have to remove the font cache, found on your system

3D plot with xkcd

Animated decaying sine curve : representing the decaying chime of a struck tuning fork at a fixed frequency -

formula: decaying sine curve
output of decaying sine curve using xkcd

This code for generating and saving animations using is very powerful and flexible: if we put some physics into the animate function and xkcd, the possibilities are endless.

This is it !! I hope you have enjoyed the journey from the boring standard graphical visualizations to comic ones with xkcd.

--

--

No responses yet