Skip to main content
 首页 » 编程设计

Python-Matplotlib : Define Individual Legend Entries

2024年08月12日30daizhj

<分区>

当我绘制以下内容时:

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() 

我得到这张图片:

对我来说,图例文本太多了。有谁知道,我如何连接蓝色和绿色实线以及蓝色和绿色虚线以将图例减少为两个带有绿色/蓝色(最好是在另一条之上)线和相应文本的条目? 感谢您的帮助