-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
lib/matplotlib/figure.py
Outdated
|
||
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``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....
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"....
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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...
|
hopefully fixed now |
PR Summary
This is an alternate approach for #20773, relying only on doc improvements.
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).