본문 바로가기
파이썬. 데이터분석/Matplotlib

matplotlib : 범례(legend)

by 한국수달보호협회장 2022. 7. 9.

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html

 

matplotlib.pyplot.legend — Matplotlib 3.5.2 documentation

Place a legend on the Axes. The call signatures correspond to the following different ways to use this method: 1. Automatic detection of elements to be shown in the legend The elements to be added to the legend are automatically determined, when you do not

matplotlib.org

matplotlib 공식사이트가면 legend 위치에 대한 상세한 설명이있다.

 

 

 

plt.plot(x, y, label='무슨데이터')
plt.legend(loc='lower right')

 

plt.plot(x, y)

plt.legend()라고치면 legend가 안뜬다.

 

plt.plot(x,y, label='무슨데이터') 이런식으로 label명칭을 정해줘야 legend가 뜬다

 

plt.legend(fontsize=18) 이런식으로 사이즈 조절 가능

plt.legend(loc=(0.4,0.6)) 디테일하게 위치 설정 가능

 

 

stateless방식

ax.legend(bbox_to_anchor=(1, 0.9),fontsize=18, loc='upper center', frameon=False, nocl=2) 

ax.legend(fancybox=True, framealpha=1, shadow=True, borderpad=1)