Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable legend on matplotlib.axes instance #2792

Closed
gnsiva opened this issue Feb 5, 2014 · 4 comments
Closed

Disable legend on matplotlib.axes instance #2792

gnsiva opened this issue Feb 5, 2014 · 4 comments

Comments

@gnsiva
Copy link

gnsiva commented Feb 5, 2014

Could we please have the functionality to disable the legend once its been instantiated?

e.g.

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

From my StackOverflow question (http://stackoverflow.com/questions/21587318/matplotlib-cancel-legend-on-axes-object?noredirect=1#comment32612205_21587318) I have been advised to request this feature.

I also found the problem could be solved with the hack:

ax.get_legend().set_visible(False)
@efiring
Copy link
Member

efiring commented Feb 5, 2014

On 2014/02/05 10:33 AM, Ganesh N Sivalingam wrote:

Could we please have the functionality to disable the legend once its
been instantiated?

e.g.

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

From my StackOverflow question
(http://stackoverflow.com/questions/21587318/matplotlib-cancel-legend-on-axes-object?noredirect=1#comment32612205_21587318)
I have been advised to request this feature.

I also found the problem could be solved with the hack:

ax.legend().set_visible(False)

Presumably you mean

ax.get_legend().set_visible(False)

That is not a hack, it is an intended use of the set_visible method.
Does it not solve your problem?

Ideally, it would also be possible to use

ax.get_legend().remove()

but this is not implemented.

Eric


Reply to this email directly or view it on GitHub
#2792.

@gnsiva
Copy link
Author

gnsiva commented Feb 6, 2014

Sorry yes that's what I meant, updated the question.
Please see the SO question as the other two commenters also thought this should be a feature.

Could there be performance implications with the potential for having several hidden legends?

Thank you

@tacaswell
Copy link
Member

@efiring I sent this over here from SO. My view is the point of this issue is to add the remove.

@pelson
Copy link
Member

pelson commented Feb 10, 2014

@cimarronm looks like #2798 has this in hand. Closing this issue in favour of that PR.

@pelson pelson closed this as completed Feb 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants