728x90
누적된 막대그래프는 각 항목의 수량을 구성하는 세부 수량을 표시하는 데 용이하다. 세부적인 항목과 전체적인 수량 비교가 가능하다.
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import seaborn as sns
if __name__ == '__main__':
sns.set_style(style="whitegrid")
tips = sns.load_dataset("tips")
print(tips.head())
bar1 = sns.barplot(x="day", y="total_bill", data=tips, estimator=sum, ci=None, color='darkblue')
smoker = tips[tips['smoker'] == 'Yes']
print(smoker.head())
bar2 = sns.barplot(x="day", y="total_bill", data=smoker, estimator=sum, ci=None, color='lightblue')
top_bar = mpatches.Patch(color='darkblue', label='smoker = No')
bottom_bar = mpatches.Patch(color='lightblue', label='smoker = Yes')
plt.legend(handles=[top_bar, bottom_bar])
plt.show()
결과 값
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
total_bill tip sex smoker day time size
56 38.01 3.00 Male Yes Sat Dinner 4
58 11.24 1.76 Male Yes Sat Dinner 2
60 20.29 3.21 Male Yes Sat Dinner 2
61 13.81 2.00 Male Yes Sat Dinner 2
62 11.02 1.98 Male Yes Sat Dinner 2
728x90
'Data Science > Data Visualization' 카테고리의 다른 글
[02. Line Chart] 001. Multi-Line Chart (0) | 2021.08.21 |
---|---|
[02. Line Chart] 001. Line Chart (0) | 2021.08.21 |
[01. Bar Chart] 004. Percentage Stacked Bar Chart (0) | 2021.08.21 |
[01. Bar Chart] 002. Horizontal Bar Chart (0) | 2021.08.21 |
[01. Bar Chart] 001. Bar Chart (0) | 2021.08.21 |