Blair  - Soul Eater [파이썬 개념] Matplotlib 2- 범례 표시하기

• programming language/python

[파이썬 개념] Matplotlib 2- 범례 표시하기

oujin 2022. 7. 21. 14:20
728x90

Matplotlib 1. 포스팅 입니다. 참고 부탁 드립니다.

 

[파이썬 개념] Matplotlib - Pyplot, plt.plot(), 제목, x,y축 이름 , 한글폰트 사용하기,plt.show()

● Matplotlib은 분석한 데이터를 그래프(Graph)나 차트(Chart)로 시각화해주는 파이썬의 패키지 라이브러리 ● Matplotlib 패키지의 Pyplot라는 모듈은 Matplotlib이 매트랩(MATLAB)처럼 동작하게 하는 명령

oujin.tistory.com

 

범례(Legend)는 그래프의 내용을 알기 위해 본보기로 표시해 둔 기호나 설명

 

●plt.legend()의 키워드 loc

'upper left', 'upper center', 'upper right', 'center left', 'center', 'center right', 'lower left', 'lower center', 'lower right'

'best' Matplotlib이 위의 9개 위치 중에서 범례를 표 시하기 가장 적합한 곳을 찾아서 위치

 

 

 

import matplotlib.pyplot as plt
from matplotlib import rc

rc('font', family='Malgun Gothic')

xdata = ['오꾸꾸', '김가나', '박축구']
ydata1 = [100, 78, 35]
ydata2 = [97, 49, 73]


plt.plot(xdata, ydata1, label='국어')
plt.plot(xdata, ydata2, label='영어')

 

#plt.legend()의 키워드 loc 의 값이 upper center : 중앙상단에 위치
plt.legend(loc='upper center')

plt.title('세명 학생의 국어, 영어 성적')

plt.show()

 

 

 

 

 

 

 

 

 

'upper left', 'upper center', 'upper right', 'center left', 'center', 'center right', 'lower left', 'lower center', 'lower right'

출처: 예제 중심 파이썬 입문

궁금한 부분이 있으면 댓글 부탁드립니다^^

728x90