Skip to main content
 首页 » 编程设计

python之matplotlib 空图例句柄

2025年05月04日16unruledboy

我想在 python 的 matplotib 图中的图例中添加一些文本。我在考虑创建一个空句柄,有什么办法吗?已经尝试使用类似于以下内容的方法:

ax.legend([handle1,handle2,None],[label1,label2,labelEmpty]) 

但图例不接受 None 关键字。 (我收到错误 $Legend 不支持无,请改用代理艺术家。$)

如果这不可能,还有其他想法吗?

我正在考虑拥有类似的东西:

 ___________________________ 
|  handle1  -  label1       | 
|  handle2  -  label2       | 
|       labelEmpty          | 
!___________________________! 

谢谢!

请您参考如下方法:

空条目和标题:

ax = gca() 
h1, h2 = ax.plot(range(5), range(5), range(5), arange(5)**2) 
 
r = matplotlib.patches.Rectangle((0,0), 1, 1, fill=False, edgecolor='none', 
                                 visible=False) 
ax.legend([h1, h2, r], ['a', 'b', 'c'], loc=0, title='test') 
plt.draw()