ENH: Support Figure.add_axes() without parameters #30968
+36
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This extends
Figure.add_axes()so that it works without parameters and creates a single subplot Axes. So far, you'd have to pass arecttuple or andAxes.In particular:
fig.add_axes()is equivalent tofig.add_subplot(); in the limiting case without parameters.plt.figure().add_axes()creates the same figure and axes objects asfig, ax = plt.subplots()plt.figure().add_axes()creates the same figure and axes objects asplt.axes()Why is this addition reasonable?
This provides yet another way to create an Axes. We already have so many ways, doesn't this add more to the confusion?
The arguments are:
Expected behavior: If I have an
add_axes()function, it's natural to expect that a can add a "default" Axes with out having to specify additional parameters.API consistency:
plt.axes()already has this behavior. By extendingfig.add_axes()we gain identical behavior on both methods.One could argue that
add_subplot()already does this, so people should use it instead. The point here is that I don't think we should stress formal distinction between subplot and Axes for one figure-filling Axes. In particular I would like to de-emphasize subplot as written in DOC: Tutorial on API shortcuts #30952 (comment)Edit Somehow the link to the comment does not work, but it's this one; please go there manually if needd:
This would also make the shortcut sequence from DOC: Tutorial on API shortcuts #30952 more consistent:
fig, ax = plt.subplots()ax = plt.figure().add_axes()ax = plt.axes()As soon as the function changes from potentially creating multiple Axes to creating only one Axes, we switch terminology from "subplots" to "axes".
Overall, since the ship on minimal axes creation API has sailed, adding one more way does not significantly worsen the complexity situation. But as a positive effect, we gain more consistency and can tell a better story on Axes creation using a subset of all that is possible.