라일락 꽃이 피는 날

[Matplotlib] 다양한 그래프 그리기 1 본문

데이터 분석/Python

[Matplotlib] 다양한 그래프 그리기 1

eunki 2021. 5. 11. 14:47
728x90

1. Scatterplot

x = np.random.rand(50)
y = np.random.rand(50)

colors = np.arange(50)
area = x * y * 1000

 

 

s: 점의 넓이 / c: 점의 색상 / cmap: 모두 같은 점의 색상 / alpha: 점의 투명도

 

 

 

 

 

 

2. Barplot, Barhplot

x = ['Math', 'Programming', 'Data Science', 'Art', 'English', 'Physics']
y = [66, 80, 60, 50, 80, 10]

 

 

 

barh 함수에서는 xticks로 설정했던 부분을 yticks로 변경

 

 

 

Batplot에서 비교 그래프 그리기

x_label = ['Math', 'Programming', 'Data Science', 'Art', 'English', 'Physics']

x = np.arange(len(x_label))
y_1 = [66, 80, 60, 50, 80, 10]
y_2 = [55, 90, 40, 60, 70, 20]

width = 0.35

 

 

 

3. Line Plot

x = np.arange(0, 10, 0.1)
y = 1 + np.sin(x)

 

 

 

2개 이상의 그래프 그리기

x = np.arange(0, 10, 0.1)
y_1 = 1 + np.sin(x)
y_2 = 1 + np.cos(x)

 

 

 

 

4. Areaplot (Filled Area)

x = np.arange(1,21)
y = np.random.randint(low=5, high=10, size=20)

 

 

fill_between으로 색칠하기 ⇒ 경계선은 굵게, area는 옅게 그리는 효과 적용

 

 

 

여러 그래프를 겹쳐서 표현

x = np.arange(1, 10, 0.05)
y_1 = np.cos(x)+1
y_2 = np.sin(x)+1
y_3 = y_1 * y_2 / np.pi

 

 

 

 

5. Histogram

N = 100000
x = np.random.randn(N)
bins = 30  # 구간

 

 

 

다중 Histogram 그리기

sharex: x축을 다중 그래프가 share

sharey: y축을 다중 그래프가 share

tight_layout: graph의 패딩을 자동으로 조절해주어 fit한 graph를 생성

 

 

 

Y축에 Density 표기

density=True: Y축에 density 표기

cumulative=True: 누적분포 표기

 

728x90