I a*_*rge 6 python plot visualization facet pandas
这就是我现在所拥有的:
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')
Run Code Online (Sandbox Code Playgroud)

如何基于'类型'绘制构面?我想要两个不同的图,一个用于type = 1,另一个用于= 2.
您需要取消堆栈type,然后使用subplots参数:
test.groupby(['week', 'type',
'type2']).agg('sum').unstack(1).plot(kind='bar', subplots=True)
Run Code Online (Sandbox Code Playgroud)
