-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Have Colorbar inherit from Axes #20341
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
Comments
Can you just make a pull of that branch, and put in Draft if you prefer? As always, I think about this sort of thing from "what would we do if we were starting over " point of view. Would we just call a colorbar a type of Axes? I guess I'm not sure... |
I wasn't sure whether an Issue was preferred before a PR for discussion purposes or not... My thought is that making a Colorbar a type of Axes would help with being able to directly override methods of the Axes, rather than having to dispatch to the |
I'm not convinced this is the right design choice. First, as you mentioned, there's a lot of additional functionality, that doesn't make much sense for colorbars. While one can question whether it's reasonable to have all the plotting methods on the Second, AFAIR the dance with the inner Axes is done to get extremes-arrows and layout work together. These might be a reason that a colorbar is fundamentally different from a regular Axes. I'm afraid we haven't clarified exactly what an Axes is. I assume it's multple things. At least:
It might be reasonable to separate these functionalities better conceptually. E.g. I think it would help if we would have layout blocks, that do not necessarily come with all the other semantics. Also factoring out the plotting functions would open up a path for others to add their own functions (whether or not we want that could be decided). We would still mix everything together for standard |
.. I mean the PR looks appealing - the question is if we want users to have that functionality directly. I'm also not clear that it is actually a simplification. i.e. I don't see how |
That is a good point about defining what an The inner/outer dance is for the extends portion, but also so that the inner can leverage the base The reason this makes it easier for something like cla() is that you can access the mappable and other Colorbar attributes from the Axes functions now: def cla(self):
self.mappable.callbacksSM.disconnect(self.mappable.colorbar_cid)
super().cla() and for the interactive Colorbar it would be nice to say |
OK, so the |
I think the concern about directly exposing the axes methods is a valid one, and indeed it will be confusing to have The desire to know if a given axes is a colorbar is a valid one. But we already do this a couple of ways. For non gridspec axes: matplotlib/lib/matplotlib/colorbar.py Line 1374 in 3cf46cb
and lines following add a For gridspec colorbar axes we don't add all the information, but the label is still set to |
... actually, now all colorbar axes should be of type |
I actually think making the API more Axes-like is easier to understand. Someone doesn't have to learn new lingo to interact with a Colorbar. A Colorbar adds a convenience helper method of
I think the issue I was running into was that the Zoom/Pan are interacting on the |
Describe the issue
A Colorbar currently stores the Axes that is used for drawing in the
cbar.ax
attribute, which many of the methods are then called internally likeself.ax.pcolormesh()
. My proposal is to move the Axes up a level and have Colorbar inherit from the newCbarAxes
class (to become an Axes itself) and turn the previous call intoself.pcolormesh()
droppingax
attribute.Benefits: This would help with interactivity as proposed in #19515, by being able to identify if an axes is a Colorbar or not and then controlling properties based on that. It would also help with #20330, by giving the CbarAxes the ability to remove colorbar callbacks.
Drawbacks: This adds a lot of easy-to-use methods onto a Colorbar now that may not be desired to directly expose to users. i.e. they could do
cbar.plot()
now, whereas beforecbar.ax.plot()
hides those capabilities a little bit more.Proposed fix
Define the class as
class ColorbarBase(ColorbarAxes):
and set
self.ax = self
for people to keep usingcbar.ax
if they prefer. We could deprecate that on pass-through as well.See this branch for an implementation.
The text was updated successfully, but these errors were encountered: