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
Conversation
@@ -1348,6 +1348,12 @@ def get_legend(self): | |||
""" | |||
return self.legend_ | |||
|
|||
def remove_legend(self): |
There was a problem hiding this comment.
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?
@efiring I remove the public method |
@@ -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 |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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
…on 2.6 does not support it
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Added remove methods for legends in figure and axes objects
travis failures are unrelated. |
This adds remove methods for legend objects. This address issue #2792