Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

add_subplot(..., axes_cls=...) #18548

Copy link
Copy link
Closed
Closed
Copy link
@anntzer

Description

@anntzer
Issue body actions

I would like to suggest adding an axes_cls parameter to add_subplot()/add_axes(), to support creating axes using custom Axes subclasses -- specifically with the idea of better integrating axes_grid/axisartist into Matplotlib.

Currently, using an axes_grid/axisartist Axes requires a rather unusual sequence of calls, of the form

from mpl_toolkits.<...> import SomeAxesSubclass
ax = SomeAxesSubclass(fig, 111, **kwargs)
fig.add_subplot(ax)  # It's quite rare to call add_subplot() with an Axes instance!

instead, I propose that one can simply write

from mpl_toolkits.<...> import SomeAxesSubclass
ax = fig.add_subplot(1, 1, 1, axes_cls=SomeAxesSubclass, **kwargs)
# or, in the common case (add_subplot defaults to 111):
ax = fig.add_subplot(axes_cls=SomeAxesSubclass, **kwargs)

Note that there is precedence in that plt.figure likewise takes a FigureClass argument for custom figure subclasses. (If we wanted to be consistent we could name the new kwarg AxesClass instead of axes_cls, but... ugh.) Also note that axes_class would conflict with the projection kwarg, because projections (e.g. polar) are also implemented as custom axes subclasses, but that's just how things are: you can't automatically combine a mpl_toolkits subclass with a projection subclass.

See also #17335 (comment).

One side advantage is that this would also make all the explicit Subplot classes (HostAxes vs. SubplotHost, axislines.Subplot vs. axislines.Axes) unnecessary: add_subplot would dynamically create the subclasses, with exactly the same machinery as it does for the normal Axes/Subplot.

I don't think the implementation will be particularly hard; as usual the hardest is deciding whether we want this or not :-)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.