xkcd Style Graphs in MATLAB

If you’re anything like me, you probably wasted an awful lot of time reading xkcd throughout your undergraduate. A colleague pointed me in the direction of a fun StackOverflow question, asking how you can generate xkcd style graphs in MATLAB.  You can download the code from Gnovice’s answer, along with the xkcd font which can be integrated into the xkcd_text.m function as per the instructions.

After the plot is generated, it may be a bit aliased (especially the xkcd font). To fix this, you can save the plot as an .eps file, and edit the raw meta data to ensure that your custom font is being used.  This can be done by opening the .eps file in a text editor, and finding the IncludeResource line.  I amended it as follows:

    %%IncludeResource: font Humor Sans
    /HumorSans /ISOLatin1Encoding 192 FMSR

The result of which, gave me this:

If you’re worried about aliasing in general on your MATLAB plots it’s worth taking a look at Anders Brun’s utility myaa.m which takes the current axes and produces an unaliased plot.  There are a few caveats, which are explained in the comments but on the whole it’s a great tool.  Thanks to Tanya Morton, for pointing me in that direction!

Leave a Reply