首页 > 解决方案 > 将图表从一个数据框中拆分为不同的类别

问题描述

如何使用 4 个不同的图表来显示 4 个不同地区(中西部、东北部、南部、西部)的不同收入?

我使用了 df.plot() 但它只显示了一行,其中包含来自所有 4 个地区的所有收入。

            Region  Revenue
Date        
2018-12-31  Midwest     652.0
2018-12-31  South       9465.3
2018-12-31  West        329.5
2018-12-31  Northeast   94063.0
2019-01-07  Midwest     2793.0
2019-01-07  South       20220.00
2019-01-07  Northeast   2544.75
2019-01-07  West        22342.35
2019-01-14  South       23434.75
2019-01-14  Midwest     23429.50
2019-01-14  West        2292.15
2019-01-14  Northeast   24520.50
2019-01-21  West        2477.00
2019-01-21  South       22355.25
2019-01-21  Midwest     28666.00

标签: pythondataframematplotlibplot

解决方案


也许pivot先使用然后再使用subplots=True

df.pivot(columns=['Region']).plot(subplots=True)

输出:

在此处输入图像描述


推荐阅读