Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
3 of 6
added 18 characters in body
slayton
  • 20.3k
  • 11
  • 63
  • 90

I know I'm late to the game on this one, but I spent a few hours on this so I'm going to share it anyway! :D

Rather than re-implmenting all the various plotting functions I wanted to create a generic tool that could convert any existing plot to a XKCD style plot.

This approach means that you can create plots and style them using standard Matlab functions and then when you're done you can then re-render the plot in an XKCD style while preserving the overall style of the plot.

Examples

Plot enter image description here

Bar & Plot

enter image description here

Box & Plot enter image description here

How it works

The function works by iterating over the children of an axes. If the children are of type line or patch it distorts them slightly. If the child is of type hggroup it then iterates on the sub-children of the hggroup. I have plans to support other plot types, such as image, but its not clear what is the best way to distort image to have an XKCD style.

Finally to ensure that the distortions look uniform (ie short lines aren't distored more than long lines) I measure the 'line' length in pixels and then up sample proportional to its length. I can then add noise every N samples which produces lines that look good regardless of how long they are.

The Code

Rather than pasting ~300 lines of code I'll just link to a gist of the source. Additionally the source code and the code to generate the above examples are freely available GitHub

As you can see from the examples it doesn't yet distort the axes themselves although I plan to implement as soon as I figure out the best way to do that.

slayton
  • 20.3k
  • 11
  • 63
  • 90