-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: add colorbar.set_aspect #22103
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
base: main
Are you sure you want to change the base?
ENH: add colorbar.set_aspect #22103
Conversation
ping @efiring. Would this address #22087 or do we need to do more major surgery? @greglucas may also have some opinions. Thanks! |
The method you have moves this up to the colorbar level, so it wouldn't help the issue where a user is explicitly calling the method on the colorbar I think the underlying issue is that diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py
index b67b108891..58c2928ea1 100644
--- a/lib/matplotlib/colorbar.py
+++ b/lib/matplotlib/colorbar.py
@@ -254,6 +254,14 @@ class _ColorbarAxesLocator:
aspect = ax._colorbar_info['aspect']
else:
aspect = False
+
+ if not isinstance(self._cbar.ax.get_aspect(), str):
+ # It was explicitly set by the user, so we need to
+ # update the stored value in colorbar_info
+ aspect = self._cbar.ax.get_aspect()
+ ax._colorbar_info['aspect'] = aspect
+ self._cbar.ax.set_aspect("auto")
+
# now shrink and/or offset to take into account the
# extend tri/rectangles.
if self._cbar.orientation == 'vertical': Perhaps creating a new def set_aspect(self, aspect, **kwargs):
self._colorbar_info["aspect"] = aspect
super().set_aspect(aspect, **kwargs)
self.ax.set_aspect = set_aspect |
Hmmm... and what about the idea of having |
I'm still trying to figure out exactly what the situations are that need to be covered, keeping in mind
|
Sorry, dropped this. The fundamental API problem is that we have an axes that helps make the colorbar, either supplied by the user, or we make one. Complicating things, we allow the user to access that axes, and some of the things we want them to twiddle we only give them twiddling access via cb.ax. However, the way we make colorbars, in particularly with extends, calling cb.ax.set_aspect is not really meaningful, as we alter the axes to be shorter to accommodate the extends and maintain the same overall aspect including the extends. To me, the best API would be that the user set the aspect on the colorbar, not the axes, which is now an implementation detail. I don't know that there is a way to prevent |
PR Summary
Replaces #20588
Closes #22087 (?)
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).