Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib取消轴对象上的图例_Python_Matplotlib - Fatal编程技术网

Python matplotlib取消轴对象上的图例

Python matplotlib取消轴对象上的图例,python,matplotlib,Python,Matplotlib,我正在使用一个外部模块,它会自动将图例添加到绘图中。 我想知道是否有关闭图例的方法,比如ax.set_图例(False) 我可以通过破解模块来修复它,但我宁愿不这么做 例如: f = plt.figure() ax = f.add_subplot(111) externalfunction(ax) # in the function ax.legend() has been called # would like to turn off the legend here plt.

我正在使用一个外部模块,它会自动将图例添加到绘图中。 我想知道是否有关闭图例的方法,比如ax.set_图例(False)

我可以通过破解模块来修复它,但我宁愿不这么做

例如:

 f = plt.figure()
 ax = f.add_subplot(111)

 externalfunction(ax)

 # in the function ax.legend() has been called
 # would like to turn off the legend here

 plt.show()
更新:

我为此提出了一个github问题

您需要更改图例的可见性,请尝试以下操作:
ax.legend()。将轴的
图例属性设置为
None
也可以完成此操作。注意后面的下划线。例如

x, y = np.random.randn(2, 30)
ax = plt.gca()
ax.plot(x, y, label="data")
ax.legend()
ax.legend_ = None

听起来未来的matplotlib版本将有一种更为官方认可的移除轴的方法,但如果在旧版本上卡住,这应该可以同时工作。

这将重新生成图例,然后使其不可见。@tcaswell(+1)我使用此技巧隐藏图例,这应该是github上的一个问题。您可以为此制作github问题吗?看起来传奇艺术家是不可移动的,但它应该是。有必要吗?我觉得Xndrome的答案满足了我的需要。@Anake tcaswell的建议是为了改进框架以备将来使用,您可以使用我的解决方案,但不应该是这样;)它似乎只做了你需要的(也就是说,你看不到传说,所以你很高兴)。但从开发人员的角度来看,这是一个非常黑客的解决方案,正确的解决方案是能够删除传说,这在技术上似乎是不可能的。(仅供参考我是mpl开发人员)@tcaswell好吧,也许你可以为我们所有人修复它:)