2014-04-10 2 views
2

내가 먼저 다음 DataFrame를 생성하여 팬더의 플롯을 생성하고 있습니다 :팬더 그룹화 바 플롯에 오차 막대를 추가

결과 dataframe은 다음과 같습니다
plotData=resultData.groupby(['student_model','lo_id']).describe().nShots.unstack().reset_index() 
plotData['se'] = plotData['std']/np.sqrt(plotData['count']) 

: 다음 enter image description here

내가 피벗 플롯과 같이 :

plotData.pivot(index='student_model',columns='lo_id',values='mean').plot(kind='bar') 

다음과 같은 결과 :

,

enter image description here

"괜찮습니다."오류 줄로 "se"열의 값을 플롯에 추가해야하며 제대로 작동하지 않습니다. 줄거리 (예 : ...plot(kind='bar', yerr=???))를 호출하기 위해 인수를 추가 할 수 있다는 것을 알고 있지만 제대로 작동하도록 제대로 형식을 지정하는 방법을 모르겠습니다. 어떤 아이디어?

답변

4

데이터를 그림으로 게시하는 것은 좋지 않습니다.

In [16]: 
#se column store the errorbar values 
print df 
    class1 class2 se val 
0  A  R 1 1 
1  A  G 1 2 
2  B  R 1 3 
3  B  G 1 4 

[4 rows x 4 columns] 
In [17]: 

df.pivot(index='class1',columns='class2',values='val').plot(kind='bar', yerr=df.pivot(index='class1',columns='class2',values='se').values) 
#or yerr=df.se.reshape((2,2)) 
#Where (2,2) is the shape of df.pivot(index='class1',columns='class2',values='val') 
#which is less verbose but may not be general 

enter image description here

: 여기에 솔루션입니다