matplotlib空图例句柄

2024-05-17 09:53:07 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

但legend不接受None关键字。(我收到错误$Legend不支持None,请改用proxy artist。$)

如果这是不可能的还有其他的想法吗?在

我想买些类似的东西:

^{pr2}$

谢谢!在


Tags: 文本none绘图关键字ax句柄图例legend
1条回答
网友
1楼 · 发布于 2024-05-17 09:53:07

空条目和标题:

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

enter image description here

相关问题 更多 >