1""" 2==== 3XKCD 4==== 5 6Shows how to create an xkcd-like plot. 7""" 8import matplotlib.pyplot as plt 9import numpy as np 10 11############################################################################### 12 13with plt.xkcd(): 14 # Based on "Stove Ownership" from XKCD by Randall Monroe 15 # http://xkcd.com/418/ 16 17 fig = plt.figure() 18 ax = fig.add_axes((0.1, 0.2, 0.8, 0.7)) 19 ax.spines['right'].set_color('none') 20 ax.spines['top'].set_color('none') 21 plt.xticks([]) 22 plt.yticks([]) 23 ax.set_ylim([-30, 10]) 24 25 data = np.ones(100) 26 data[70:] -= np.arange(30) 27 28 plt.annotate( 29 'THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED', 30 xy=(70, 1), arrowprops=dict(arrowstyle='->'), xytext=(15, -10)) 31 32 plt.plot(data) 33 34 plt.xlabel('time') 35 plt.ylabel('my overall health') 36 fig.text( 37 0.5, 0.05, 38 '"Stove Ownership" from xkcd by Randall Monroe', 39 ha='center') 40 41############################################################################### 42 43with plt.xkcd(): 44 # Based on "The Data So Far" from XKCD by Randall Monroe 45 # http://xkcd.com/373/ 46 47 fig = plt.figure() 48 ax = fig.add_axes((0.1, 0.2, 0.8, 0.7)) 49 ax.bar([0, 1], [0, 100], 0.25) 50 ax.spines['right'].set_color('none') 51 ax.spines['top'].set_color('none') 52 ax.xaxis.set_ticks_position('bottom') 53 ax.set_xticks([0, 1]) 54 ax.set_xlim([-0.5, 1.5]) 55 ax.set_ylim([0, 110]) 56 ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT']) 57 plt.yticks([]) 58 59 plt.title("CLAIMS OF SUPERNATURAL POWERS") 60 61 fig.text( 62 0.5, 0.05, 63 '"The Data So Far" from xkcd by Randall Monroe', 64 ha='center') 65 66plt.show() 67