-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Adding cla and remove to ColorbarAxes #20323
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
Conversation
The cla and remove methods need to be applied to both the inner and outer axes.
b9a0dc2
to
51db38e
Compare
I don't think it's this easy. What happens if you pass different length extends to the second colorbar call? Cla is not adequate to change the colorbar. |
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'll block just to stop this getting merged too fast. The semantics of cla on a colorbar axes are not the same as a normal axes.
It is a little strange to clear a colorbar axes, and/or reuse it. Why are you doing this? I'm 90% sure Certainly as it stands, this PR is adding and cb = fig_test.colorbar(pc, extend='both')
# Clear and re-use the same colorbar axes
cb.ax.cla()
cb = fig_test.colorbar(pc, cax=cb.ax) won't work. I suppose that
but I'm not 100% sure that garbage collects properly. |
I agree, I'm not entirely sure how useful/practical this is. It came up when I was looking into the tests for axes_grid where the cax is being re-used, and I was trying to see if the same thing happens for regular axes with the state sharing. I couldn't even test that case because there isn't a remove method on the CbarAxes, so it throws an error currently. matplotlib/lib/mpl_toolkits/tests/test_axes_grid.py Lines 43 to 47 in 08f4629
|
I guess changing the mappable associated with the colorbar is a reasonable use-case. If we think the semantics of |
I think it is reasonable to expect that This is pushing towards type promotion being the better option here as it lets us "demote" the Axes back to a normal axes in colorbar probably also needs to pick up some logic to say "if the cax I've been given has already been promoted at least once, re-use the inner/outer logic rather than re-adding it". I now suspect (but have not chased through to be sure) that this is the core issue in #19553 's failing tests. |
I guess the question is if #19553 was failing before #20054 was rebased into it. However, that test passed #20054, so I'm not clear why this PR causes problems.
I agree that demoting is the right thing. I'm not quite sure what you mean by "type promotion", and I don't see anything in the conversations of #20054. If you mean casting the original axes to |
def cla(self):
"""
Reset the colorbar axes to be empty.
"""
# need to low-level manipulate the stacks because we
# are just swapping places here. We don't need to
# set transforms etc...
self.figure._axstack.add(self)
self.figure._axstack.remove(self.outer_ax)
self.figure._localaxes.add(self)
self.figure._localaxes.remove(self.outer_ax)
self.__dict__.update(self.outer_ax.__dict__)
self.inner_ax.remove()
del self.inner_ax
del self.outer_ax
self.xaxis.set_visible(True)
self.yaxis.set_visible(True)
for spine in self.spines.values():
spine.set_visible(True)
self.set_facecolor('white') seems to work fine, except the callback for the mappable gets called while the axes is in the indeterminate state for some reason, so we need a try/except on Setting all the axis visibility/facecolor is a bit hokey, as we should probably set the state to what it was before colorbar was called? But I'm not sure anyone is going to be using the axes for anything but a new colorbar, so maybe that is OK? |
Closing in favor of #20330 |
PR Summary
Noticed while testing re-using the same axes to place a new colorbar in. These methods need to be applied to both axes.
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).