2016-09-08 2 views
4

현재이 코드 : 이것은 .plot() 호출 subplots=True를 사용서브 그림과 색상에 대해 다른 변수가있는 팬더 플롯?

bar plot with too much shit on it

나에게 가져옵니다 : 꽤 쓸모

useless subplots

count_df = (df[['rank', 'name', 'variable', 'value']] 
    .groupby(['rank', 'variable', 'name']) 
    .agg('count') 
    .unstack()) 
count_df .head() 
#    value       
# name   1lin STH_km27_lin ST_lin S_lin 
# rank variable         
# 1.0 NEE   24   115  33 28 
#  Qg   23   54  14  9 
#  Qh   37   124  11 28 
# ... 
count_df.plot(kind='bar') 

나에게이 음모를 가져옵니다 , 색상이 subplot facetting과 같은 변수. name (count_df 열 머리글) 당 색상을 가질 수 있도록 서브 플로팅에 사용할 열/인덱스를 선택할 수있는 방법이 있지만 variable에 대한 하위 플롯은 각 하위 플롯에 name/rank, 그룹화되어 rank이고 색이 name입니까?

답변

2

Hrm. 나는 이것이 그 자체로 팬더에서하지 행할 생각,하지만 난 시본에서 할 수있는 방법을 발견 :

import seaborn as sns 

cdf = (df[['rank', 'name', 'variable', 'value']] 
      .groupby(['rank', 'variable', 'name']) 
      .agg('count')) 
sns.factorplot(x="rank", y="value", row="variable", hue="name", 
       data=cdf.reset_index(), kind='bar') 

결과 :

barplot by rank, variable, and name

내 목적을 위해 충분히 가까운

관련 문제