8000 Have Colorbar inherit from Axes · Issue #20341 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Have Colorbar inherit from Axes #20341
Open
@greglucas

Description

@greglucas

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 like self.ax.pcolormesh(). My proposal is to move the Axes up a level and have Colorbar inherit from the new CbarAxes class (to become an Axes itself) and turn the previous call into self.pcolormesh() dropping ax 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 before cbar.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 using cbar.ax if they prefer. We could deprecate that on pass-through as well.

See this branch for an implementation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0