-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
add_subplot(..., axes_cls=...) #18548
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
What does this get us versus the existing |
It means that all the subclasses don't need to do an extra registration step, which I guess axisgrid doesn't do? I think its less mysterious to pass the class than import and then pass to the class rather than import and then pass a string that we have to look up? |
Since the I also would not be a fan of deprecating |
Certainly, you could also abuse the projection mechanism for passing axes subclasses that have nothing to do with projections, which has actually been done in the wild(!): https://github.com/astrofrog/mpl-scatter-density#scatter_density-method, but let's say that ax1 = SubplotHost(fig, 1, 2, 2, grid_helper=grid_helper)
fig.add_subplot(ax1) would now read ax1 = fig.add_subplot(1, 2, 2, axes_cls=HostAxes, grid_helper=grid_helper) Personally I've always thought that the first snippet felt extremely... unmatplotlibish (it's quite rare on the user-facing side to have to explicitly instantiate artists by calling the class constructor), whereas the second snippet feels more natural ("it's just a normal add-a-subplot-thing"). I guess even ax1 = fig.add_subplot(1, 2, 2, projection="axisartist.HostAxes", grid_helper=grid_helper) (or even
expanding |
Do we mind aliases? if so I'd do
and add an alias kwarg |
To summarize:
So the idea is reasonable, the only question is how to define the API.
|
I don't think that I prefer |
|
closed by #18573. |
I would like to suggest adding an
axes_cls
parameter toadd_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
instead, I propose that one can simply write
Note that there is precedence in that
plt.figure
likewise takes aFigureClass
argument for custom figure subclasses. (If we wanted to be consistent we could name the new kwargAxesClass
instead ofaxes_cls
, but... ugh.) Also note thataxes_class
would conflict with theprojection
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 :-)
The text was updated successfully, but these errors were encountered: