python pandas DataFrame subplot in columns and rows python pandas DataFrame subplot in columns and rows pandas pandas

python pandas DataFrame subplot in columns and rows


In current versions of Pandas, DataFrame.plot features the layout keyword for this purpose.

df.plot(subplots=True, layout=(2,2), ...)


cplcloud's answer works, but following code will give you a bit more structure so that you can start configuring more if you do not need the loop.

fig, axes = plt.subplots(nrows=2, ncols=2)fig.set_figheight(6)fig.set_figwidth(8)df[0].plot(ax=axes[0,0], style='r', label='Series'); axes[0,0].set_title(0)df[1].plot(ax=axes[0,1]); axes[0,1].set_title(1)df[2].plot(ax=axes[1,0]); axes[1,0].set_title(2)df[3].plot(ax=axes[1,1]); axes[1,1].set_title(3)fig.tight_layout()

Added some example on axis 0 to show how you can further configure it.