Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 파이썬 시각화
- tensorflow
- MATLAB
- 월간결산
- 한빛미디어서평단
- 한빛미디어
- Linux
- Pandas
- 시각화
- 파이썬
- 블로그
- 텐서플로
- 통계학
- Ga
- Python
- 티스토리
- 독후감
- Tistory
- 리눅스
- SQL
- matplotlib
- Google Analytics
- python visualization
- 서평
- Visualization
- 딥러닝
- 매틀랩
- MySQL
- Blog
- 서평단
Archives
- Today
- Total
pbj0812의 코딩 일기
[PYTHON] stackplot 으로 Age Of Empires 그래프 그리기 본문
ComputerLanguage_Program/PYTHON
[PYTHON] stackplot 으로 Age Of Empires 그래프 그리기
pbj0812 2021. 7. 18. 19:090. 목표
- stackplot 으로 Age Of Empires 그래프 그리기

1. 실습
1) library 호출
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
2) 데이터 프레임 생성
df = pd.DataFrame({
'A' : [np.random.randint(1, 10) for i in range(100)],
'B' : [np.random.randint(1, 10) for i in range(100)],
'C' : [np.random.randint(1, 10) for i in range(100)]})

3) 인덱스를 시간으로 대체
df.index = pd.date_range('1/1/2000', periods=100, freq='M')

4) 합계 계산
df['Total'] = df['A'] + df['B'] + df['C']

5) 각 나라별 퍼센테이지 계산
df['A2'] = df['A'] / df['Total'] * 100
df['B2'] = df['B'] / df['Total'] * 100
df['C2'] = df['C'] / df['Total'] * 100

6) 그림 작성
fig, ax = plt.subplots()
fig.set_size_inches(15, 10)
ax.set_xlim(df.index[0], df.index[-1])
ax.set_ylim(0, 100)
color_map = ["#f0dc6c", "#9e9c90", "#5f7ba1"]
ax.stackplot(df.index,df['A2'], df['B2'], df['C2'], colors = color_map)
ax.set_title('Achievements', fontsize = 20)
ax.set_ylabel("Player's Population Percentage", fontsize = 15)
ax.set_xlabel("Time(year)", fontsize = 15)
ax.text(df.index[0], df['A2'][0] / 2 , 'A2', fontsize = 20)
ax.text(df.index[0], (df['A2'][0] + df['A2'][0] + df['B2'][0]) / 2, 'B2', fontsize = 20)
ax.text(df.index[0], (df['A2'][0] + df['B2'][0] + 100) / 2, 'C2', fontsize = 20);

2. 참고
- How to change the color palette for stackplot, matplotlib?
'ComputerLanguage_Program > PYTHON' 카테고리의 다른 글
[PYTHON] bar 그래프에 백분율 표시하기 (0) | 2021.07.22 |
---|---|
[PYTHON] streamlit 으로 대시보드 만들기 (0) | 2021.07.21 |
[PYTHON] pandas-bokeh 라이브러리 써보기 (0) | 2021.07.16 |
[PYTHON] relativedelta 를 활용한 date_add 구현 (0) | 2021.07.15 |
[PYTHON] pandas query 함수 사용하기 (0) | 2021.07.09 |
Comments