-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix interaction between sticky_edges and shared axes. #16450
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
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 |
---|---|---|
|
@@ -2436,14 +2436,25 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True): | |
if tight is not None: | ||
self._tight = bool(tight) | ||
|
||
if self.use_sticky_edges and ( | ||
(self._xmargin and scalex and self._autoscaleXon) or | ||
(self._ymargin and scaley and self._autoscaleYon)): | ||
stickies = [artist.sticky_edges for artist in self.get_children()] | ||
else: # Small optimization. | ||
stickies = [] | ||
x_stickies = np.sort([x for sticky in stickies for x in sticky.x]) | ||
y_stickies = np.sort([y for sticky in stickies for y in sticky.y]) | ||
x_stickies = y_stickies = np.array([]) | ||
if self.use_sticky_edges: | ||
# Only iterate over axes and artists if needed. The check for | ||
# ``hasattr(ax, "lines")`` is necessary because this can be called | ||
# very early in the axes init process (e.g., for twin axes) when | ||
# these attributes don't even exist yet, in which case | ||
# `get_children` would raise an AttributeError. | ||
if self._xmargin and scalex and self._autoscaleXon: | ||
x_stickies = np.sort(np.concatenate([ | ||
artist.sticky_edges.x | ||
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. Even w/ the comment, the 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. It doesn't matter which children you pick, the point is that for twinned axes this is called even before the lines attribute is created (i.e. the first time 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 believe you, but this seems to be a band-aid rather than fixing the underlying issue, which is that I don't understand how 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. Yes, but cla() calls 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. Can we change
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 I think this is more likely to hide bugs -- normally no one should call get_children() that early in the axes init process, so I'd rather just workaround this in the sole place I know this can happen. But I can also apply your patch if you really prefer 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. Its just really mystifying why the check would be there, even with the comment. 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. It is a shorthand for "is the Axes actually built yet?". Agree it would be better if we could be sure that we never call this method before the Axes is fully set up, but short of re-writing the Axes init process (which is if I understand it one of our biggest performance bottle knecks) and making sure things like this that need to be computed don't get computed until as late as possible, we have to put a band-aid someplace. I agree with @anntzer that putting this check in We can't put the fix outside of this function because we may need the rest of it to run. We could explicitly add state |
||
for ax in self._shared_x_axes.get_siblings(self) | ||
if hasattr(ax, "lines") | ||
for artist in ax.get_children()])) | ||
if self._ymargin and scaley and self._autoscaleYon: | ||
y_stickies = np.sort(np.concatenate([ | ||
artist.sticky_edges.y | ||
for ax in self._shared_y_axes.get_siblings(self) | ||
if hasattr(ax, "lines") | ||
for artist in ax.get_children()])) | ||
if self.get_xscale().lower() == 'log': | ||
x_stickies = x_stickies[x_stickies > 0] | ||
if self.get_yscale().lower() == 'log': | ||
|
Uh oh!
There was an error while loading. Please reload this page.