1

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!

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

8 Comments

Amazing. you helped me alot to figure this one out! just, whata bout the open new figure for max num of cols?
you could use layout=(-1, 6) for example, if you wanted maximum 6 columns
I think i wasnt clear, i want to show all the pallets that i have information on. with the layout above. but if there are like 10 columns i want to be able to open a new window with the rest f the columns, but in the same 2*3 layout (as you shows above) thanks again my friend
btw can you explain why the -1 makes it dynamic?
It is just a clever convention built into pandas, - similar to numpy.reshape - here are the docs: pandas.pydata.org/pandas-docs/stable/user_guide/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.