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

Added remove methods for legends in figure and axes objects #2798

Merged
merged 4 commits into from Feb 10, 2014

Conversation

cimarronm
Copy link
Contributor

This adds remove methods for legend objects. This address issue #2792

@@ -1348,6 +1348,12 @@ def get_legend(self):
"""
return self.legend_

def remove_legend(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not see another public method added here; normally one removes an artist by calling that artist's remove method. Wouldn't that be adequate in this case?

@cimarronm
Copy link
Contributor Author

@efiring I remove the public method remove_legend in axes

@@ -5,7 +5,7 @@
from six.moves import xrange

import mock
from nose.tools import assert_equal
from nose.tools import assert_equal, assert_is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nose tools wrap python's unittest module, and unfortunately it appears assertIs wasn't introduced until 2.7. As a result, with Python2.6 this test gets an ImportError, and the nose test claims:

ERROR: Failure: AttributeError ('module' object has no attribute 'test_legend')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/nose/loader.py", line 402, in loadTestsFromName
    module = resolve_name(addr.module)
  File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/nose/util.py", line 321, in resolve_name
    obj = getattr(obj, part)
AttributeError: 'module' object has no attribute 'test_legend'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll change it to use a plain old assert statement then

@@ -509,6 +509,7 @@ def legend(self, *args, **kwargs):
raise TypeError('Invalid arguments to legend.')

self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
self.legend_._remove_method = lambda h: setattr(self, 'legend_', None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the unused lambda argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The artist remove method calls _remove_method with self so it needs an argument even if not used.

Otherwise you get

TypeError: <lambda>() takes 0 positional arguments but 1 was given

@tacaswell tacaswell added this to the v1.4.x milestone Feb 10, 2014
tacaswell added a commit that referenced this pull request Feb 10, 2014
Added remove methods for legends in figure and axes objects
@tacaswell tacaswell merged commit 8aec3fb into matplotlib:master Feb 10, 2014
@tacaswell
Copy link
Member

travis failures are unrelated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants