<2가지 비교사항을 막대바로 정렬해보기>

# 한국어 폰트 적용

import matplotlib
# matplotlib.rcParams['font.family'] = 'Malgun Gothic' # 윈도우즈의 '맑은 고딕'설정
matplotlib.rcParams['font.family'] = 'AppleGothic'    # 맥북 '애플 고딕'설정

matplotlib.rcParams['axes.unicode_minus'] = False

 

<Before, After 설정>

members_id= ['m_01','m_02','m_03','m_04']
before_wo = [27,35,40,33]
after_wo = [30,38,42,37]

 

# plt.bar

# 세로막대기
import matplotlib.pyplot as plt
import numpy as np

n_data = len(members_id) # 4명
index_1 = np.arange(n_data) # Numpy 배열 (0,1,2,3)

plt.bar(index_1, before_wo, tick_label=members_id) # bar(x,y)에서 x=index, y= before_wo
plt.title('Before 세로막대기')
plt.show()

 

 

 

# 가로 막대 그래프를 생성
colors =['r','g','b','m']
plt.barh(index_1,after_wo, color=colors, tick_label = members_id)  # barh <- h만 넣어주면 됨
plt.title('After 세로막대기')
plt.show()

 

<2가지 세로막대기 생성으로 비교해보기>

# 하나의 창에서 두 개의 그래프를 그리자.
barwidth = 0.4
plt.bar(index_1,before_wo, color='c', align='edge', width=barwidth, label='before')
plt.bar(index_1+barwidth,after_wo, color='m', align='edge', width=barwidth, label='after')
plt.legend() # 범례
plt.xlabel('회원 ID')
plt.ylabel('근육량')
plt.title('운동 전후의 근육변화량 비교')
plt.show()

 

'AI > [Visualization]' 카테고리의 다른 글

[Seaborn] Seaborn 그래프 형태  (0) 2023.02.13
[Matplotlib] Pie그래프  (0) 2023.02.13
[Matplotlib] 산점도 찍기  (0) 2023.02.13
[Matplotlib] 시각화 첫 단계  (0) 2023.02.07

+ Recent posts