Matplotlib undo legend on axes object

I use an external module that automatically adds a legend to the plot. I would like to know if there is a way to disable the legend, something like ax.set_legend (False).

I could fix this by hacking the module, but I would not do it.

Example:

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

Update:

I raised a github question for this https://github.com/matplotlib/matplotlib/issues/2792

+3
source share
2 answers

You need to change the visibility of your legend, try the following: ax.legend().set_visible(False)

+3
source

You can also do this by setting the legend_axis attribute to None. Pay attention to the underline. For instance.

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

, matplotlib , / .

+3

All Articles