Dataframe:子图中不同图中的每列

问题描述 投票:1回答:1

我有一个熊猫数据帧,我希望每个子列在每个子图上表示(2维)

我知道pandas的默认子图是所需的输出但是1维:

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()

输出:

enter image description here

我希望能够输出每列但在二维子图中。对于常见的X和Y,列长度是动态的,所以我希望能够在每个图上放置6列,如果num pallets> 6打开一个新的同形图。

所以我希望它看起来像那样:

enter image description here

但有共同的X和Y.

谢谢!

python pandas dataframe plot
1个回答
2
投票

IIUC你可以用layout方法指定the .plot arg。例如:

生成2行3列的子图。

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

生成超过2行的子图,并动态计算列。

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

如果您需要子图共享轴,您可以通过sharexsharey

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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.