Remove the legend on a matplotlib figure

后端 未结 8 1140
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 19:01

To add a legend to a matplotlib plot, one simply runs legend().

How to remove a legend from a plot?

(The closest I came to this

8条回答
  •  眼角桃花
    2020-11-30 19:38

    As of matplotlib v1.4.0rc4, a remove method has been added to the legend object.

    Usage:

    ax.get_legend().remove()
    

    or

    legend = ax.legend(...)
    ...
    legend.remove()
    

    See here for the commit where this was introduced.

提交回复
热议问题