import numpy as np # deals with numbers in arrays
import matplotlib.pyplot as plt # good for plottin'
# plotly
x = np.linspace(0, 10, 500)
y = np.sin(x)
y1 = np.cos(x)
y2 = np.random.randint(10, size=(500))/10
fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(8,3))
ax1.plot(x,y, lw='20')
ax1.set_title('plot 1')
ax2.plot(x,y1)
ax2.set_title('plot 2')
ax3.scatter(x,y2)
ax3.set_title('plot 3')
plt.tight_layout()
plt.show()
fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(8,6), sharex='col', sharey='row')
# you can loop over axes:
# for i, ax in enumerate(fig.axes):
# ax.set_ylabel('subplot ' + str(i))
# fill up some plots as above but now with 2D array allocation [row,col]
# row 0
axs[0,0].plot(x,y)
axs[0,0].set_title('plot 1')
axs[0,0].set_ylabel('subplot row 1')
axs[0,1].plot(x,y1)
axs[0,1].set_title('plot 2')
axs[0,2].plot(x,y2)
axs[0,2].set_title('plot 3')
# row 1
axs[1,0].scatter(x,y)
axs[1,1].scatter(x,y1)
axs[1,2].scatter(x,y2)
# row 2
axs[2,0].bar(x,y*100)
axs[2,1].bar(x,y1*100)
axs[2,2].bar(x,y2*100)
plt.subplots_adjust(hspace=0, wspace=0)
#plt.tight_layout()
plt.show()
with plt.xkcd():
# This figure will be in XKCD-style
fig1 = plt.figure()
plt.plot(x,y)
# ...
plt.show()
findfont: Font family ['xkcd', 'xkcd Script', 'Humor Sans', 'Comic Neue', 'Comic Sans MS'] not found. Falling back to DejaVu Sans.