데이터분석/Python matplotlib

<Python Matplotlib> Stack Plot 누적 그래프 그리기

창조적생각 2021. 8. 20. 09:32

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from matplotlib import pyplot as plt
 
 
#그래프 스타일입니다.
plt.style.use("fivethirtyeight")
 
 
#x축에 표시될 수치들입니다.
minutes = [1,2,3,4,5,6,7,8,9]
 
 
#각 분마다 player들이 획득한 점수입니다.
player1 = [1,2,3,3,4,4,4,4,5]
 
player2 = [1,1,1,1,2,2,2,3,4]
 
player3 = [1,1,1,2,2,2,3,3,3]
 
 
#색은 파랑 빨강 초록입니다.
colors = ['008fd5','#fc4f30','#6d904f']
 
 
 
labels = ['player1','player2','player3']
 
 
 
 
#plt.stackplot로 만듭니다.
plt.stackplot(minutes,player1,player2,player3, labels = labels, colors=colors)
 
 
#https://matplotlib.org/stable/api/legend_api.html 에 들어가시면 레이블의 위치를 자세히 설명해줍니다.
plt.legend(loc='upper left')
 
 
 
plt.title('my stack plot')
 
plt.tight_layout()
 
plt.show()
cs

 

728x90