ENH: add colorbar.set_aspect - #22103
Conversation
|
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
pytestpasses).flake8-docstringsand 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).