当我绘制以下内容时:
plt.plot([0,1],[0,1],'g',label='Solid')
plt.plot([0,1],[.5,1],'b',label='Solid')
plt.plot([0,1],[1,0],'g--',label='Dashed')
plt.plot([0,1],[.5,0],'b--',label='Dashed')
plt.legend()
我得到这张图片:
对我来说,这是太多的图例文字。有谁知道,我如何才能将蓝色和绿色的实线以及蓝色和绿色的虚线连接起来,以使图例减少为带有绿色/蓝色(最好是一个在另一个顶部)和相应文本的两个条目?感谢您的帮助
查看legend()
,即legend()
的可能签名。>
legend(handles, labels)
中也有很好的描述。
Legend Tutorial
line1, = plt.plot([0,1],[0,1],'g',label='Solid') line2, = plt.plot([0,1],[.5,1],'b',label='Solid') plt.plot([0,1],[1,0],'g--',label='Dashed') plt.plot([0,1],[.5,0],'b--',label='Dashed') plt.legend((line1, line2), ('green', 'blue')) plt.show()