Skip to content

Document how to check for the existence of current figure/axes. #20783

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

Merged
merged 1 commit into from
Aug 4, 2021

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Aug 2, 2021

PR Summary

This is an alternate approach for #20773, relying only on doc improvements.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).


If no current Axes exists, a new one is created using `.add_subplot`.
(To test whether an Axes exists on a Figure, check whether
``figure.axes`` is empty. To test whether a current Figure exists,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``figure.axes`` is empty. To test whether a current Figure exists,
``figure.axes`` is empty. To test whether any figures exist,

I appreciate that you mean a "current figure" as in a figure on the figure stack, but that technical distinction reads strangely, and I don't think needs to be made here. Ditto below....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong preference, but note that the current wording parallels the first sentence ("if no current Axes exists"). Would you change that too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because gca stands for "get current axes"....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's the same as gcf() which stands for get current figure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the docs for gcf. You could be more technical and say "To test whether there are any figures in the gcf() stack," But the phrase "to test whether a current Figure exists" just reads a typo/bad grammar with no context.

If we want we could change "Get the current Axes from the pyplot Axes stack" to be more explicit as well. (and maybe replace "stack" by something more correct?)

Copy link
Contributor Author

@anntzer anntzer Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think I see the problem. I pushed a rewording, does that look better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. This could go in regardless of #20773...

@QuLogic
Copy link
Member

QuLogic commented Aug 3, 2021

/home/circleci/project/lib/matplotlib/pyplot.py:docstring of matplotlib.pyplot.gca:4: WARNING: more than one target found for cross-reference 'add_subplot': matplotlib.figure.Figure.add_subplot, matplotlib.figure.FigureBase.add_subplot, matplotlib.figure.SubFigure.add_subplot

@anntzer
Copy link
Contributor Author

anntzer commented Aug 4, 2021

hopefully fixed now

@QuLogic QuLogic added this to the v3.5.0 milestone Aug 4, 2021
@QuLogic QuLogic merged commit 89645b8 into matplotlib:master Aug 4, 2021
@anntzer anntzer deleted the cfa branch August 4, 2021 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants