Skip to content

Instantly share code, notes, and snippets.

@bastelflp
Last active November 29, 2015 18:47
Show Gist options
  • Save bastelflp/868037a6a5df8755a3b8 to your computer and use it in GitHub Desktop.
Save bastelflp/868037a6a5df8755a3b8 to your computer and use it in GitHub Desktop.
Python xkcd plot
# idea from http://jakevdp.github.io/blog/2013/07/10/XKCD-plots-in-matplotlib/
# needs the font 'Humor Sans' from http://antiyawn.com/uploads/humorsans.html
# clear matplotlib font cache after font installation: %userprofile%\.matplotlib\fontList.cache
import matplotlib.pyplot as plt
import numpy as np
def main():
x = np.linspace(-4, 14, 120)
plt.xkcd()
plt.plot(x, np.sin(x) * np.exp(-0.1 * (x - 5)**2), 'b', lw=2, label='damped sin')
plt.plot(x, -np.cos(x) * np.exp(-0.1 * (x - 5)**2), 'r', lw=2, label='damped cos')
plt.title('check this out!')
plt.xlabel('x label')
plt.ylabel('y label')
plt.legend(loc='lower right')
plt.xlim(-4.1, 14.1)
plt.ylim(-1.1, 1.1)
plt.show()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment