import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
fig = plt.figure(figsize=(10, 8))
outer = gridspec.GridSpec(2, 2, wspace=0.2, hspace=0.2)
for i in range(4):
inner = gridspec.GridSpecFromSubplotSpec(2, 1,
subplot_spec=outer[i], wspace=0.1, hspace=0.1)
for j in range(2):
ax = plt.Subplot(fig, inner[j])
t = ax.text(0.5,0.5, 'outer=%d, inner=%d' % (i, j))
t.set_ha('center')
ax.set_xticks([])
ax.set_yticks([])
fig.add_subplot(ax)
fig.show()
# new style method 1; unpack the axes
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex=True, sharey=True)
ax1.plot(x)
# Build the plot
fig, ax = plt.subplots()
ax.bar(x_pos, CTEs, yerr=error, align='center', alpha=0.5, ecolor='black', capsize=10)
ax.set_ylabel('Coefficient of Thermal Expansion ($degree C^{-1}$)')
ax.set_xticks(x_pos)
ax.set_xticklabels(materials)
ax.set_title('Coefficent of Thermal Expansion (CTE) of Three Metals')
ax.yaxis.grid(True)
# Save the figure and show
plt.tight_layout()
plt.savefig('bar_plot_with_error_bars.png')
plt.show()
subplot(m,n,p) %Creates subplot of m rows and n columns and assigns to plot in
p index of mxn subplot matrix.
fig, (ax1, ax2,ax3,ax4,ax5) = plt.subplots(1,5)
# Whatever you want your values to be:-
ax1.plot([1,2,3,4,5], [1,2,3,4,10], 'go')
ax2.plot([1,2,3,4,5], [2,3,4,5,11], 'b*')
#X labels:-
ax1.set_xlabel('whatever you want')
ax2.set_xlabel('whatever you want')
ax3.set_xlabel('whatever you want')
ax4.set_xlabel('whatever you want')
ax5.set_xlabel('whatever you want')
#You can do same with Y axis