
- seaborn
- seaborn은 matplotlib과 함께 실행된다.
- seaborn은 import하는 것만으로도 뭔가 효과를 준다.
- white스타일
sns.set_style(“white”)
plt.figure(figsize=(10, 6))
plt.plot(x, y1, x, y2, x, y3, x, y4)
sns.despine()
plt.show()
- dark스타일
sns.set_style(“dark”)
plt.figure(figsize=(10, 6))
plt.plot(x, y1, x, y2, x, y3, x, y4)
sns.despine()
plt.show()
- whitegrid스타일
sns.set_style(“whitegrid”)
plt.figure(figsize=(10, 6))
plt.plot(x, y1, x, y2, x, y3, x, y4)
sns.despine()
plt.show()
- despine적용
plt.figure(figsize=(10, 6))
plt.plot(x, y1, x, y2, x, y3, x, y4)
sns.despine(offset=10)
plt.show()
- seaborn에는 실습용 데이터가 몇 개 내장되어 있다.
- 이 중 하나 tips를 불러보기
- boxplot그리기 가능
plt.figure(figsize=(8, 6))
sns.boxplot(x=tips[“total_bill])
plt.show()
- boxplot에 컬럼을 지정
plt.figure(figsize=(8, 6))
sns.boxplot(x=”day“, y=”total_bill“, data=tips)
plt.show()
- 컬럼을 지정하고 구분 지을 수 있음
- swarmplot
plt.figure(figsize=(8, 6))
sns.swarmplot(x=”day“, y=”total_bill“, data=tips, color=”.5“)
plt.show()
- boxplot을 swarmplot의 콜라보
plt.figure(figsize=(8,6))
sns.boxplot(x=“day”, y=“total_bill”, data=tips)
sns.swarmplot(x=“day”, y=“total_bill”, data=tips, color=“.25”)
plt.show()
- pivot옵션을 사용할 수 있다.
- heatmap을 이용하면 전체 경향을 알 수 있다.
- colormap을 조금 다르게 설정 가능
- iris데이터도 있다.
- 다수의 컬럼을 비교하는 pairplot
- pairplot에서는 hue 옵션
- 원하는 컬러만 pairplot가능
- 데이터 시각화
- 앞에서 했던 matplotlib의 한글 폰트 잡기
- 윈도우 : Malgun Gothic
- pairplot으로 강도, 살인, 폭력에 대한 상관관계 확인
- 인구수, CCTV와 살인 강도와의 관계도 확인
- 인구수, CCTV와 살인/폭력 검거율의 관계 확인
- 인구수, CCTV와 절도/강도 검거율 확인
- 검거율만 가지고 heatmap
- 단, 전거 검거율의 대푯값인 검거를 기준으로 정렬
- 범죄발생 건수로도 heatmap
- 대푯값인 범죄를 기준으로 정렬