Adjusting subplot layout with pandas Adjusting subplot layout with pandas pandas pandas

Adjusting subplot layout with pandas


tight_layout() definitely works with pandas!

without tight_layout()

df.T.plot(kind='bar', subplots=True, width=0.7, legend=False,                              layout=(3, 2), sharex=True, sharey=True)# plt.tight_layout()

enter image description here


with tight_layout()

df.T.plot(kind='bar', subplots=True, width=0.7, legend=False,                              layout=(3, 2), sharex=True, sharey=True)plt.tight_layout()

enter image description here


As pointed out by piRSquared pointed out tight_layout() definitely works. However, the layout should be exactly agreeing with the number of subplots.

Pandas automatically removes empty subplots and thus figure layouts with more than the required number of subplots will cause the error stated above.

Here is my own solution to the problem. As simple as it gets.

Using plt.subplots_adjust() one can easily adjust the required parameters after plotting the figure.