본문 바로가기

Crawling/데이터 시각화

데이터시각화_10가지_Histogram

파이썬 시각화 차트 종류

1. Column/Bar chart
2. Dual Axis, 파레토 chart
3. Pie chart
4. Line chart
5. Scatter chart
6. Bubble chart
7. Heat map
8. Histogram
9. Box plot
10. Geo chart

 

 

# 208.py

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
marathon_2015_2017 = pd.read_csv('./data_boston/marathon_2015_2017.csv')
print(marathon_2015_2017.shape)
marathon_2015_2017.head(3)

 

(1) 나이별 참가자 비율 분포 구하기 : 씨본의 distplot

# figure size 지정
plt.figure(figsize = (20, 10))

# displot 함수로 분포 그리기
age_count = sns.distplot(marathon_2015_2017.Age, rug=True, kde=True)

# 제목, x라벨 ,y라벨 지정
age_count.set_title('Distribution Rate by Ages', fontsize=18)
age_count.set_xlabel('Ages', fontdict={'size':16})
age_count.set_xlabel('Distibution Rate', fontdict={'size':16})

plt.show()

 

(2) 나이별 참가자 실제 수 그리기 : 씨본의 countplot

# figure size 지정
plt.figure(figsize = (20, 10))

# displot 함수로 분포 그리기
age_count = sns.countplot(marathon_2015_2017.Age)

# 제목, x라벨 ,y라벨 지정
age_count.set_title('Distribution by Ages', fontsize=18)
age_count.set_xlabel('Ages', fontdict={'size':16})
age_count.set_xlabel('Distibution Rate', fontdict={'size':16})

plt.show()

 

(3) 카운트가 높은 연령 기준으로 실제 수 그리기 : 씨본의 countplot 응용

marathon_2015_2017['Age'].value_counts().index
# figure size 지정
plt.figure(figsize = (20, 10))

# displot 함수로 분포 그리기
# 카운트가 높은 연령 기준으로 : value_counts와 index 메소드를 이용해서
age_count = sns.countplot('Age', data=marathon_2015_2017, order=marathon_2015_2017['Age'].value_counts().index)

# 제목, x라벨 ,y라벨 지정
age_count.set_title('Distribution by Ages sorted', fontsize=18)
age_count.set_xlabel('Ages', fontdict={'size':16})
age_count.set_xlabel('Distibution Rate', fontdict={'size':16})

plt.show()