Amit Neuhaus
Amit Neuhaus

Reputation: 183

Dataframe : each column in different plot in subplot

I have a panda Dataframe which I want each column to be represented on each subplot( 2 dimensions)

i know the default subplot of pandas is the desired output but 1 dimensional:

pallet       45   46   47   48   49   50
date
2019-04-15  4.0  NaN  2.0  NaN  NaN  2.0
2019-04-16  3.0  2.0  2.0  2.0  1.0  1.0
2019-04-17  2.0  2.0  2.0  2.0  1.0  1.0
2019-04-18  2.0  2.0  2.0  NaN  1.0  1.0
2019-04-19  2.0  2.0  2.0  NaN  1.0  1.0
2019-04-20  2.0  2.0  2.0  NaN  1.0  NaN
pivot.plot(subplots=True)
plt.show()

output:

enter image description here

I want to be able to output each column but in 2-dimensional subplots. with common X and Y the columns length is dynamic so i want to be able to put like 6 columns on each figure, if num pallets > 6 open a new same-shaped figure.

so I want it to look like that:

enter image description here

but with common X and Y

Thank you!

Upvotes: 1

Views: 1911

Answers (1)

Chris Adams
Chris Adams

Reputation: 18647

IIUC you can specify the layout arg in the .plot method. For example:

To generate subplots of 2 rows and 3 columns.

pivot.plot(subplots=True, layout=(2, 3))

To generate subplots over 2 rows, with columns being dynamically calculated.

pivot.plot(subplots=True, layout=(2, -1))

And if you need the subplots to share axis, you can pass sharex or sharey

pivot.plot(subplots=True, layout=(2, -1), sharex=True, sharey=True)

enter image description here

Upvotes: 2

Related Questions