-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: ColorbarAxes properly in the axes stack #20484
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 | ||||
---|---|---|---|---|---|---|
|
@@ -227,9 +227,9 @@ def __init__(self, parent, userax=True): | |||||
True if the user passed `.Figure.colorbar` the axes manually. | ||||||
""" | ||||||
|
||||||
fig = parent.figure | ||||||
if userax: | ||||||
# copy position: | ||||||
fig = parent.figure | ||||||
outer_ax = fig.add_axes(parent.get_position()) | ||||||
# copy the locator if one exists: | ||||||
outer_ax._axes_locator = parent._axes_locator | ||||||
|
@@ -239,28 +239,48 @@ def __init__(self, parent, userax=True): | |||||
parent._axes.add_child_axes(outer_ax) | ||||||
outer_ax._axes.child_axes.remove(parent) | ||||||
else: | ||||||
parent.remove() | ||||||
try: | ||||||
parent.remove() | ||||||
except ValueError: | ||||||
pass # Already removed | ||||||
else: | ||||||
outer_ax = parent | ||||||
|
||||||
# swap axes in the stack if its in there: | ||||||
if outer_ax in fig._localaxes: | ||||||
fig._localaxes.remove(outer_ax) | ||||||
fig._axstack.remove(outer_ax) | ||||||
fig._localaxes.add(self) | ||||||
fig._axstack.add(self) | ||||||
inner_ax = outer_ax.inset_axes([0, 0, 1, 1]) | ||||||
self.__dict__.update(inner_ax.__dict__) | ||||||
|
||||||
self.outer_ax = outer_ax | ||||||
self.inner_ax = inner_ax | ||||||
|
||||||
self.outer_ax.xaxis.set_visible(False) | ||||||
self.outer_ax.yaxis.set_visible(False) | ||||||
self.outer_ax.set_facecolor('none') | ||||||
self.outer_ax.tick_params = self.inner_ax.tick_params | ||||||
self.outer_ax.set_xticks = self.inner_ax.set_xticks | ||||||
self.outer_ax.set_yticks = self.inner_ax.set_yticks | ||||||
for attr in ["get_position", "set_position", "set_aspect"]: | ||||||
for attr in ["get_position", "set_aspect", | ||||||
"_remove_method", "_set_position", | ||||||
"set_position", "cla", "draw"]: | ||||||
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'm still not sure about these only being mapped to the outer_ax... I would have thought it should be something like: def draw(self, renderer):
super().draw(renderer)
self.outer_ax.draw(renderer) so that you draw both the inner and outer? Same for the cla and remove. The position's I think are appropriate to map straight to the outer though. 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. inner is an artist on outer, so inner gets drawn if outer gets drawn ;-) 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. Oh yeah, it is an inset of the outer! Makes sense now, thanks for clarifying. |
||||||
setattr(self, attr, getattr(self.outer_ax, attr)) | ||||||
self._colorbar_info = None # used for mpl-created axes | ||||||
if hasattr(self.outer_ax, "get_subplotspec"): | ||||||
attr = "get_subplotspec" | ||||||
setattr(self, attr, getattr(self.outer_ax, attr)) | ||||||
|
||||||
if userax: | ||||||
self._colorbar_info = 'user' | ||||||
# point the parent's methods all at this axes... | ||||||
origdict = parent.__dict__ | ||||||
parent.__dict__ = self.__dict__ | ||||||
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 you just update it?
Suggested 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. Oh, maybe? Thanks! 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, sadly not. I'll admit I'm probably not enough of a pythionista to dig around in the guts like this. Its pretty apparent to me that this copies all the attributes over, but if you iterate through 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. Maybe try |
||||||
for key in origdict.keys(): | ||||||
if key not in parent.__dict__: | ||||||
parent.__dict__[key] = origdict[key] | ||||||
|
||||||
def _set_inner_bounds(self, bounds): | ||||||
""" | ||||||
|
@@ -949,8 +969,7 @@ def remove(self): | |||||
If the colorbar was created with ``use_gridspec=True`` the previous | ||||||
gridspec is restored. | ||||||
""" | ||||||
self.ax.inner_ax.remove() | ||||||
self.ax.outer_ax.remove() | ||||||
self.ax.remove() | ||||||
|
||||||
self.mappable.callbacksSM.disconnect(self.mappable.colorbar_cid) | ||||||
self.mappable.colorbar = 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.
I'm not sure how it wouldn't be there if you've created it above or gotten it passed in? But, wouldn't you want to
add(self)
regardless of whether the outer one is there or not?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.
There was some test where we made a colorbar and it didn't actually ever get added. I can take ti out again to figure out which one...