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: https://imgur.com/E61XREF.jpg

i want to be able to ouput 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: https://imgur.com/8GxWEah but with common X and Y

Thank you!

1 answer

  • answered 2019-04-21 10:21 Chris A

    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