Looking at matplotlib documentation, I found this example:
http://matplotlib.org/users/tight_layout_guide.html
import matplotlib.pyplot as plt
def example_plot(ax,pid, fontsize=12):
ax.plot([1, 2])
ax.locator_params(nbins=3)
ax.set_xlabel('x-label', fontsize=fontsize)
ax.set_ylabel('y-label', fontsize=fontsize)
ax.set_title('Title'+str(pid), fontsize=fontsize)
plt.close('all')
fig = plt.figure()
ax1 = plt.subplot(221)
ax2 = plt.subplot(223)
ax4 = plt.subplot(122)
example_plot(ax1,1)
example_plot(ax2,2)
example_plot(ax4,4)
plt.tight_layout()
plt.show()
which produce a 2 columns layout, on the left a column with two rows, and on the right a column with 1 row. This seems to match what the API of subplot is saying: http://matplotlib.org/api/pyplot_api.html
subplot(211) produces a subaxes in a figure which represents the top plot (i.e. the first) in a 2 row by 1 column notional grid (no grid actually exists, but conceptually this is how the returned subplot has been positioned).
I am now trying to add a row to the column of the left (for a total of 3 rows). From my understanding, that should do it:
import matplotlib.pyplot as plt
def example_plot(ax,pid, fontsize=12):
ax.plot([1, 2])
ax.locator_params(nbins=3)
ax.set_xlabel('x-label', fontsize=fontsize)
ax.set_ylabel('y-label', fontsize=fontsize)
ax.set_title('Title'+str(pid), fontsize=fontsize)
plt.close('all')
fig = plt.figure()
ax1 = plt.subplot(321) # changed "2" by "3"
ax2 = plt.subplot(323) # changed "2" by "3"
ax3 = plt.subplot(324) # line added
ax4 = plt.subplot(122)
example_plot(ax1,1)
example_plot(ax2,2)
example_plot(ax3,3) # line added
example_plot(ax4,4)
plt.tight_layout()
plt.show()
There is something I must be doing wrong, because this display the right layout, but the third plot of the first column does not show up ....