xxxxxxxxxx
subplot(m,n,p) %Creates subplot of m rows and n columns and assigns to plot in
p index of mxn subplot matrix.
xxxxxxxxxx
# Create a facetted graph with 2 rows and 2 columns
ax = df.plot(subplots=True,
layout=(2,2),
sharex=False,
sharey=False,
linewidth=0.7,
fontsize=3,
legend=False)
# Alternative way
fig, ax = plt.subplots(2, 2)
ax[0, 0].plot( )
ax[0, 0].set_title("first row first column")
ax[1, 0].plot( )
ax[1, 0].sharex(ax[0, 0]) # Share same range with each other
ax[1, 0].set_xlabel("X label")
# ...and so on
fig.tight_layout()
plt.show()
xxxxxxxxxx
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
xxxxxxxxxx
# 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()
xxxxxxxxxx
# new style method 1; unpack the axes
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex=True, sharey=True)
ax1.plot(x)