최대 1 분 소요

3. 범례(Legend)

import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'Malgun Gothic' # 글자 폰트
matplotlib.rcParams['font.size'] = 15 # 글자 크기
matplotlib.rcParams['axes.unicode_minus'] = False # 한글 폰트 사용 시, 마이너스 글자가 깨지는 현상을 해결
x = [1, 2, 3]
y = [2, 4, 8]
plt.plot(x,y, label='무슨 데이터')
plt.legend()
<matplotlib.legend.Legend at 0x1f10a6118e0>

plt.plot(x,y, label='무슨 데이터')
plt.legend(loc='lower right') # 범례 위치 변경
<matplotlib.legend.Legend at 0x1f10d0b0d60>

plt.plot(x,y, label='범례')
plt.legend(loc=(0.7, 0.3)) # x축, y축 [0~1 사이] 
<matplotlib.legend.Legend at 0x1f10d17f580>

댓글남기기