Skip to content

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

@anntzer

Description

@anntzer

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy