2015-04-22 86 views
4

这就是我现在所拥有的:如何绘制小地块在大熊猫

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

enter image description here

如何绘制方面基于“型”?我想两个不同的地块,一个用于type = 1和另一种类型= 2

+0

你可能看看seaborn(基于熊猫和matplotlib)http://stanford.edu/~mwaskom/software/seaborn/tutorial/axis_grids.html – JohnE

回答

3

你需要拆散所以type都柱,然后使用subplots参数:

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

enter image description here