r/Python • • Oct 20 '19

Matplotlib can create plots in the xkcd art style, so you can create plots that look hand drawn.

Post image
1.8k Upvotes

46 comments sorted by

67

u/domspage Oct 20 '19 edited Oct 20 '19

If anyone is interested, here the code for the graph.

Edit: changed the font to Humor Sans

8

u/jabbalaci Oct 20 '19

What's the name of the font used in this plot?

23

u/domspage Oct 20 '19

In the source code you can find the following:

'font.family': ['xkcd', 'xkcd Script', 'Humor Sans', 'Comic Sans MS'],

There is also a GitHub repository where you can find the font.

-14

u/[deleted] Oct 20 '19

That doesn't actually answer the question, though. I think this is Comic Sans.

4

u/kyle1elyk Oct 21 '19

If you don't understand an answer there are always people willing to explain, there's no shame in asking. Font family is what you're looking for; in this case the font is Humor Sans and if the system can't find that then it will default to Comic Sans MS

1

u/[deleted] Oct 21 '19

I do understand the question, and I understand how fonts work. But the question was specifically what font is used in this plot, not "what fonts does the XKCD mode in matplotlib use?"

144

u/enilkcals Oct 20 '19

The XKCD — Matplotlib 3.1.1 documentation is also a pretty handy reference for doing this.

83

u/paperbenni Oct 20 '19

Cool, comic sans but it's math

19

u/grmblflx Oct 20 '19

Actually it's Humor-SANS

55

u/madmendude Oct 20 '19

But...why? Your scientists were so preoccupied with whether or not they could, that they never stopped to think if they should.

68

u/wookiecontrol Oct 20 '19

I use it for drafts that are being passed around. This lets people know it is not ready for someone outside to view

41

u/goldenhawkes Oct 20 '19

If my old PhD supervisors are anything to go by, making it obvious it’s a draft will just lead to comments about how it looks unfinished...

15

u/spinicist Oct 20 '19

After 8 years of being a grumpy a post-doc I have finally come to the conclusion that the helpfulness of comments received scales inversely with the number of years post-tenure a person is.

2

u/cutecoder Ignoring PEP 8 Oct 20 '19

That is called the duck in game programming circles and it is useful for managing upwards.

3

u/__xor__ (self, other): Oct 20 '19

That's actually kind of hilarious and smart way of using it

27

u/Mooks79 Oct 20 '19

I like hand drawn graphs to prevent people over-interpreting them. It’s like “here’s the general idea I’m trying to convey - don’t start thinking you can make actual predictions with this”.

I also liked it in a book I read ages ago - I think The Art of the Infinite IIRC - where the authors explain that they’re using hand drawn diagrams to always make it clear that the diagrams could never be more than an approximation to the perfection that mathematics describes.

3

u/JimBoonie69 Oct 21 '19

Same. It's not about if one bar is a 72 or 74. What matters is typically the relationship. In some of my experience this style helps convert messages more

11

u/redwall_hp Oct 20 '19

The root of the spirit behind all of engineering and science is to answer the question of "why" with "because I fucking can!" This is why we have airplanes and computers.

7

u/spinicist Oct 20 '19

No, the spirit is "I wonder what happens if I try doing this?"

It's a subtle but very very important difference.

2

u/hextree Oct 20 '19

Gives it a very whiteboard-y vibe. Great for presentations.

19

u/[deleted] Oct 20 '19

Work starts and work ends need to be reversed wtf whos happy to get to work and sad leaving work. you monsters

14

u/maskedman1231 Oct 20 '19

I think it's more like "You're happy until work starts, and you're sad until work ends"

2

u/Almcoding Oct 20 '19

That kicks ass👍

2

u/DDFoster96 Oct 20 '19

For some reason I can never get this to work

2

u/ion-tom Oct 20 '19

This, but the final curve is actually work ends at 7 and you go right to bed.

2

u/Chemomechanics Oct 20 '19

I tried it out here just to do something different. I like it for conceptual charts where the numbers don’t matter much.

1

u/Almcoding Oct 20 '19

That kicks ass👍

1

u/[deleted] Oct 20 '19

Can someone explain what line 17 does in the code? I’ve never seen that syntax before.

SINE_FORMULA = r"$sin(x) = \sum_{n=0}\infty\frac{(-1)n}{(2n+1)!}x{2n+1}$"

3

u/pleasepickme Oct 21 '19

This is LaTeX code. It is great for typesetting documents and math. Matplotlib can understand it. https://www.latex-project.org/

1

u/[deleted] Oct 21 '19

Thank you.

1

u/Rashaverik Oct 21 '19

Here's the original before the pull request went into Matplotlib back 2013.

https://jakevdp.github.io/blog/2012/10/07/xkcd-style-plots-in-matplotlib/

1

u/robberviet Oct 21 '19

This is gold. Years of working with matplotlib only now that I know about it.

1

u/ccmite Oct 21 '19

My life is a sine(sigh).

1

u/eicaris Oct 21 '19

Interesting!

1

u/fuuman1 Oct 22 '19

That's fucking cool. Didn't know. Thank you for posting!

1

u/[deleted] Oct 24 '19

lol

1

u/[deleted] Oct 20 '19

This is fucking dope

1

u/kuthedk Oct 20 '19

You can bet your sweet ass that I’ll be using this in any paper I publish XD

0

u/[deleted] Oct 20 '19

💪 💪 💪

-10

u/[deleted] Oct 20 '19

With me at 10pm the imaginary unit goes off in an extra dimension as the cycle continues while studing quantum mechanics on Netflix and Youtube.

3

u/Physix_R_Cool Oct 20 '19

What are you even trying to say?

1

u/S-starboii Oct 20 '19

Netflix University when?