2014-09-18 4 views
0

해적 인 Factorplot (kind = bar)을 사용하여 2 개의 "카테고리"(각 카테고리에 3 개의 막대)에서 총 6 개의 막대를 나타냅니다. 스택 디자인을 사용하여이 factorplot을 향상시키고 싶습니다. 즉 각 막대를 "하위 구성 요소"로 나타내려고합니다. 이것이 barplot에서도 가능하지만 factorplot에서도 가능하다는 것을 알고 있습니까?Seaborn Factorplot에서 "stacked"디자인을 사용하십시오.

+0

쇼 데이터의 구조를 보여줍니다 당신이 이미 시도했습니다 whay 몇 가지 코드를. –

답변

1

랜디 Zwitch explains seaborn에 누적 막 대형 차트를 만드는 방법.

해결 방안은 막대 그래프의 아래쪽 부분이 앞쪽에 있고 후속 부분의 가장 아래 부분을 흐리게 표시하도록 누적 막대 그래프를 같은 그래프에 여러 개 겹쳐서 표시하는 것으로 생각하는 것입니다.

는 자신의 블로그에서 인용 :

import pandas as pd 
from matplotlib import pyplot as plt 
import matplotlib as mpl 
import seaborn as sns 
%matplotlib inline 

#Read in data & create total column 
stacked_bar_data = pd.read_csv("C:\stacked_bar.csv") 
stacked_bar_data["total"] = stacked_bar_data.Series1 + stacked_bar_data.Series2 

#Set general plot properties 
sns.set_style("white") 
sns.set_context({"figure.figsize": (24, 10)}) 

#Plot 1 - background - "total" (top) series 
sns.barplot(x = stacked_bar_data.Group, y = stacked_bar_data.total, color = "red") 

#Plot 2 - overlay - "bottom" series 
bottom_plot = sns.barplot(x = stacked_bar_data.Group, y = stacked_bar_data.Series1, color = "#0000A3") 


topbar = plt.Rectangle((0,0),1,1,fc="red", edgecolor = 'none') 
bottombar = plt.Rectangle((0,0),1,1,fc='#0000A3', edgecolor = 'none') 
l = plt.legend([bottombar, topbar], ['Bottom Bar', 'Top Bar'], loc=1, ncol = 2, prop={'size':16}) 
l.draw_frame(False) 

#Optional code - Make plot look nicer 
sns.despine(left=True) 
bottom_plot.set_ylabel("Y-axis label") 
bottom_plot.set_xlabel("X-axis label") 

#Set fonts to consistent 16pt size 
for item in ([bottom_plot.xaxis.label, bottom_plot.yaxis.label] + 
      bottom_plot.get_xticklabels() + bottom_plot.get_yticklabels()): 
    item.set_fontsize(16) 
관련 문제