这就是我现在所拥有的:

np.random.seed(1234)
test = pd.DataFrame({'week': [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2],
                     'score': np.random.uniform(0, 1, 12),
                     'type': [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
                     'type2': [3, 3, 4, 4, 5, 5, 3, 3, 4, 4, 5, 5]})

test.groupby(['week', 'type', 'type2']).agg('sum').unstack().plot(kind='bar')

如何根据“类型”绘制构面?我想要两个不同的图,一个用于类型= 1,另一个用于类型= 2。

最佳答案

您需要先进行堆叠,以便type为列,然后使用subplots参数:

test.groupby(['week', 'type',
              'type2']).agg('sum').unstack(1).plot(kind='bar', subplots=True)

关于python - 如何在 Pandas 中绘制多面图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29786227/

10-12 17:24