【问题标题】:matplotlib empty legend handlesmatplotlib 空图例句柄
【发布时间】:2013-06-05 14:07:05
【问题描述】:

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

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

但是 legend 不接受 None 关键字。 (我得到错误 $Legend does not support None, Use proxy artist instead.$)

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

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

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

谢谢!

【问题讨论】:

    标签: python matplotlib plot data-visualization legend


    【解决方案1】:

    空条目和标题:

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

    【讨论】:

    • 谢谢。 title='Line 1\nLine2' 也可以。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多