-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
It is painful as a new user, to figure out what AxesSubplot is #18222
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
As a remark, Would have a more descriptive docstring of |
I'm pretty sure plt.gca() was returning an AxesSubplot. See #18220 for the code. Anything that fixes the online docs and/or increases the probability that a user will quickly understand that AxesSubplot is an Axes, would be an improvement. I'm not sure the current docstring but if it's the one from |
Can you be a bit more specific about what changes to the documentation would have helped? As a side note, my go-to tools when exploring new classes (looking at the mro and isinstance checks) In [13]: isinstance(plt.gca(), matplotlib.axes.Axes)
Out[13]: True
In [14]: type(plt.gca()).mro()
Out[14]:
[matplotlib.axes._subplots.AxesSubplot,
matplotlib.axes._subplots.SubplotBase,
matplotlib.axes._axes.Axes,
matplotlib.axes._base._AxesBase,
matplotlib.artist.Artist,
object] both seem pretty clear. |
Thomas, I agree. Those things are clear. If it wasn't clear above, the specific fixes I recommend are:
As things currently stand, AxesSubplot is frequently encountered when using matplotlib but isn't even mentioned in the docs. This leads to many questions about what it might be, whether it is a true Axes or (per its name) doing some special forwarding or modified behaviors for contained Axes of subplots, etc ... and when one goes to find the source code to make sure it's the Axes you want to be talking to ... you end up not finding it easily because it's name appears nowhere in the source code either. I hope that helps :) Matplotlib is awesome. |
I agree this is painful. Its made worse by the fact that we use a factory to create the subclass, so its really hard as a beginner interested in the internals to trace how the class is even defined. It would be nice to figure out a reasonable place to explain this. |
In principle, it should be possible to document dynamically created classes in Sphinx because AFAIK it uses introspection and no static code analysis. |
I think adding the sentence "AxesSubplot" is a dynamically created class inheriting SubplotBase" in the docstring of |
Actually, looking at it again, I think it may be reasonable to just push all the SubplotBase functionality either to the base Axes class (with |
just wanted to say I agree with the sentiment of pain with |
AxesSubplot is going away; the deprecation machinery is already in (cf mpl.axes._subplots), now someone (mostly) just needs to pull the thread and remove everything... |
thanks @anntzer, I noticed that. I guess you are suggesting not to deal with it all, which would mean me not using fig, axes = plt.subplots(n_rows, n_cols, figsize) that doesn't depend on any subplot mechanism, and returns the "unadulterated" native I am assuming GridSpec only deals with geometry (and not create axes), and the new mosaic compositional mechanism still returns AxesSubplots: from matplotlib import pyplot as plt
fig = plt.figure(constrained_layout=True)
ax_dict = fig.subplot_mosaic(
[
["bar", "plot"],
["hist", "image"],
],
)
ax_dict
Out[22]:
{'bar': <AxesSubplot:label='bar'>,
'plot': <AxesSubplot:label='plot'>,
'hist': <AxesSubplot:label='hist'>,
'image': <AxesSubplot:label='image'>} i have created grids of axes before e.g. in the Thanks you for help. |
FWIW: TIL what |
For anyone who found this and is not yet on v3.7, know that |
Ouch - PRs gratefully accepted, even for post-facto improvements to the release notes - sometimes things get overlooked with the finite developer time at our disposal https://github.com/matplotlib/matplotlib/blob/main/doc/users/prev_whats_new/whats_new_3.7.0.rst |
Please see discussion at #25228 (comment) as to why we did not consider this an API change. |
Sorry @jklymak I didn't mean it in an ouchy way at all, I actually thought it was quite funny that the elusive |
This is a good example of why text-only communication is hard! Reading your message with a joking tone of voice is funny (that class is a ghost and disappeared like one) vs and angry one (the good for nothing devs once again changed things) induce very different responses. |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Try googling "AxesSubplot" which is the type you get back from a plt.gca() call. Try finding this class in the docs. Try searching for this class in the source code.
Poor new users trying to figure out what they're dealing with...
(It's a dynamic class created in _subplot.py that is a subclass of Axes, but ... boy was that a pain to detangle. Asked it's class for it's module, etc... Have mercy on new users and make it easier to find documentation for dynamic classes.)
(and no, it's not good enough that google does show Axes in its result, because it's not AxesSubplot, and if you're chasing down an AttributeError, or have a typo in a function call that you believe it "should" respond to, you're in a mindset of thinking "this must not be an Axes")
The text was updated successfully, but these errors were encountered: