-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
fix the stack remove error #7335
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
Changes from all commits
db343c3
25492ce
23cfcda
6932d7c
0ab7a30
9d2d33e
23a8d73
33318e3
6dc9248
4c72fe7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,15 @@ New in matplotlib 2.0 | |
|
||
matplotlib 2.0 supports Python 2.7, and 3.4+ | ||
|
||
The behavior of AxesStack re-add key changes | ||
-------------------------------------------- | ||
|
||
The AxesStack does not allow users to re-add the same key. If the user tries | ||
to do so, a KeyError will be raised. | ||
If the user really wants to re-add the same key, then the old one should | ||
be removed first by using :func:`AxesStack.remove` and re-add the new key. | ||
|
||
:func:`~figure.AxesStack.add` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be leftover from something. |
||
|
||
|
||
Default style changes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,12 +125,10 @@ def add(self, key, a): | |
except TypeError: | ||
raise ValueError("first argument, %s, is not a valid key" % key) | ||
|
||
a_existing = self.get(key) | ||
a_existing = dict(self._elements).get(key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does reaching into the internals and casting it to a dict fixes this bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the casting is there because there was a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not follow 😞 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refer to this JunTan@db343c3#diff-c3ce78ddcc28c54e04ade080c149c1b1R130 There was a Then we decide to remove Thus the casting fixes the bug of the call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I now see that the underlying |
||
if a_existing is not None: | ||
Stack.remove(self, (key, a_existing)) | ||
warnings.warn( | ||
"key %s already existed; Axes is being replaced" % key) | ||
# I don't think the above should ever happen. | ||
raise KeyError('Key %s already exists in the AxesStack' % key) | ||
# This only happens if user call this function directly | ||
|
||
if a in self: | ||
return None | ||
|
@@ -362,7 +360,7 @@ def _repr_html_(self): | |
# We can't use "isinstance" here, because then we'd end up importing | ||
# webagg unconditiionally. | ||
if (self.canvas is not None and | ||
'WebAgg' in self.canvas.__class__.__name__): | ||
'WebAgg' in self.canvas.__class__.__name__): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably match the exact class name instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pep8 modification, so no need to hold this PR on that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, my point was "this should be something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually the whole condition should just get rewritten as |
||
from matplotlib.backends import backend_webagg | ||
return backend_webagg.ipython_inline_display(self) | ||
|
||
|
@@ -816,7 +814,7 @@ def _make_key(self, *args, **kwargs): | |
'make a hashable key out of args and kwargs' | ||
|
||
def fixitems(items): | ||
#items may have arrays and lists in them, so convert them | ||
# items may have arrays and lists in them, so convert them | ||
# to tuples for the key | ||
ret = [] | ||
for k, v in items: | ||
|
@@ -1745,7 +1743,7 @@ def subplots_adjust(self, *args, **kwargs): | |
if not isinstance(ax, SubplotBase): | ||
# Check if sharing a subplots axis | ||
if (ax._sharex is not None and | ||
isinstance(ax._sharex, SubplotBase)): | ||
isinstance(ax._sharex, SubplotBase)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just make this |
||
ax._sharex.update_params() | ||
ax.set_position(ax._sharex.figbox) | ||
elif (ax._sharey is not None and | ||
|
@@ -1921,8 +1919,8 @@ def figaspect(arg): | |
# could become rc parameters, for now they're hardwired. | ||
figsize_min = np.array((4.0, 2.0)) # min length for width/height | ||
figsize_max = np.array((16.0, 16.0)) # max length for width/height | ||
#figsize_min = rcParams['figure.figsize_min'] | ||
#figsize_max = rcParams['figure.figsize_max'] | ||
# figsize_min = rcParams['figure.figsize_min'] | ||
# figsize_max = rcParams['figure.figsize_max'] | ||
|
||
# Extract the aspect ratio of the array | ||
if isarray: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,13 @@ | |
import six | ||
from six.moves import xrange | ||
|
||
from nose.tools import assert_equal, assert_true | ||
from matplotlib import rcParams | ||
from nose.tools import assert_equal, assert_true, assert_raises | ||
from matplotlib import rcParams, figure | ||
from matplotlib.testing.decorators import image_comparison, cleanup | ||
from matplotlib.axes import Axes | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import warnings | ||
|
||
|
||
@cleanup | ||
|
@@ -216,6 +217,17 @@ def test_figaspect(): | |
assert h / w == 1 | ||
|
||
|
||
@cleanup | ||
def test_stack_remove(): | ||
a = figure.AxesStack() | ||
key = '123' | ||
axes = plt.figure().add_subplot(111) | ||
a.add(key, axes) | ||
# Verify some things | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is something supposed to come after this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, sorry , it should come before the assertion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the comment be more specific? |
||
assert_raises(KeyError, a.add, key, plt.figure().add_subplot(111)) | ||
assert_equal(a._elements, [(key, (1, axes))]) | ||
|
||
|
||
if __name__ == "__main__": | ||
import nose | ||
nose.runmodule(argv=['-s', '--with-doctest'], exit=False) |
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'm not sure
AxesStack
is what should be documented here; it's an internal (if not private) implementation detail and what the user really sees is thatFigure.add_axes
(andplt.axes
?) no longer has this behaviour. "What's new" should be about user-visible changes. This specific information could probably go inapi/api_changes
.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.
Agreed that this should be moved to the api_changes and cleaned up (see @QuLogic's comment below).