本文介绍了删除matplotlib图上的图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要将图例添加到matplotlib图中,只需运行legend()
.
To add a legend to a matplotlib plot, one simply runs legend()
.
如何从剧情中删除图例?
(我最接近的是运行legend([])
以便从数据中清空图例.但这在右上角留下了一个难看的白色矩形.)
(The closest I came to this is to run legend([])
in order to empty the legend from data. But that leaves an ugly white rectangle in the upper right corner.)
推荐答案
截至 matplotlib v1.4.0rc4
,一个remove
方法已添加到图例对象.
As of matplotlib v1.4.0rc4
, a remove
method has been added to the legend object.
用法:
ax.get_legend().remove()
或
legend = ax.legend(...)
...
legend.remove()
有关引入的提交,请参见此处.
See here for the commit where this was introduced.
这篇关于删除matplotlib图上的图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!