시작전에 실행할 코드
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
마이너스 기호 깨짐 방지
윈도우 맑은 고딕 설정
plt.rcParams['font.family'] = 'Malgun Gothic'
plt.rcParams['axes.unicode_minus'] = False
맥 애플고딕 설정
plt.rcParams['font.family'] = 'AppleGothic'
plt.rcParams['axes.unicode_minus'] = False
[ pyplot 방식 ]
import matplotlib.pyplot as plt
1 도화지(크기) 준비
plt.figure(figsize=(8, 5))
2. 데이터 플로팅 (선, 막대, 산점도 등)
plt.plot(x, y, label='데이터 이름')
3. 그래프 구성 요소 추가 (데코레이션)
plt.title('그래프 제목')
plt.xlabel('X축 이름')
plt.ylabel('Y축 이름')
plt.grid(True)
plt.legend()
4. 출력 및 닫기
plt.show()
[객체 지향 구조] - 여러 그래프 배치가능
import matplotlib.pyplot as plt
1. 도화지(fig)와 그래프 구역(ax)을 분리하여 생성
fig, ax = plt.subplots(figsize=(8, 5))
2. 생성한 구역(ax)에 그래프 그리기
ax.plot(x, y, label='데이터 이름')
3. 구역(ax)의 속성 설정 (★ 이 방식은 주로 set_ 메서드를 사용합니다)
ax.set_title('그래프 제목')
ax.set_xlabel('X축 이름')
ax.set_ylabel('Y축 이름')
ax.grid(True)
ax.legend()
4. 출력
plt.show()
✨ ax = fig.add_subplot(2, 2, 1)
: 가로 2등분 , 세로 2등분 했을때 1번째 칸
✨ plt.figure(figsize=(8,4))
: 실무에서 많이 쓰는 크기
: plt.plot
ex) plt.plot(arr, color="pink", marker="*", linestyle="-.")