Matplotlib XY Line 그래프 전설
-
21-12-2019 - |
문제
IPYTHON 노트북의 내부, MATPLOTLIB의 XY LINE 그래프에 전설을 추가하는 방법은 무엇입니까? 내 현재 시도 :
x = np.linspace(0, 3*np.pi, 500)
a = plt.plot(x, np.sin(x**2))
b = plt.plot(x, np.sin(x**0.5))
plt.legend([a,b], ['square', 'square root'])
.
이렇게하면 다음과 같은 오류가 발생합니다.
/users/mc/.virtualenvs/kaggle/lib/python2.7/site-packages/matplotlib/legend.py:613 : UserWarning : 범례는 [] 대신 프록시 아티스트를 사용하지 않습니다.
http://matplotlib.sourceforge.net/users/legend_guide. HTML # 프록시 아티스트 사용
(str (orig_handle))) /users/mc/.virtualenvs/kaggle/lib/python2.7/site-packages/matplotlib/legend.py:613 : UserWarning : 범례는 [] 대신 프록시 아티스트를 사용하지 않습니다.
http://matplotlib.sourceforge.net/users/legend_guide. HTML # 프록시 아티스트 사용
(str (orig_handle))))
이 명령은 plt.scatter
대신 plt.plot
를 수행하면 x, y 포인트 대신 줄 그래프를 원합니다.
해결책
어떻게해야합니까?
x = np.linspace(0, 3*np.pi, 500)
fig, ax = plt.subplots()
a = ax.plot(x, np.sin(x**2), label = 'square')
b = ax.plot(x, np.sin(x**0.5), label = 'square root')
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels)
.
이 기능을 얻으려면 :
제휴하지 않습니다 StackOverflow