Repository navigation
Conversation
|
Name should probably be something with "create", e.g. "allow_create" or "create_if_none". |
|
create_if_none it is (for now) |
timhoffm
left a comment
There was a problem hiding this comment.
At first I was hesitant to touch gca() at all, because it's deeply tied into the pyplot state, and generally I think that's best left in peace.
However, I agree that something has to be done: gca() does two things: 1. obtaining the current axes, 2. creating a new one if needed. While the combination is often what people want in pyplot, it's a shortcoming that we cannot easily check whether a current axes exists.
I'm +/-0 on this solution to the problem. I'm hesitant with a create_if_none kwarg because gca() has a very particular but well established functionality. The create_if_none extension is straight forward, but adds a additional functionality that makes understanding gca() a bit harder. Before the functionality was really only "Get the current Axes, creating one if necessary." Now, we have to make a distinction in case there is no default Axes.
Please consider an explicit plt.has_current_axes() function as an alternative and give your opinion which solution is better.
Side question: For symmetry, should we have a similar behavior for the current figure?
|
I actually do not understand this PR at all, particularly compared to #20770. The problem in that issue is that we no longer search the stack for matching kwargs to gca(). I don't see what this PR has to do with that? |
|
@timhoffm @jklymak I'm specifically adressing the following point in @dstansby's issue:
|
|
I assume that people rarely want to know if there is a current axes (otherwise the request should have come more early/often). So maybe we can get by with documenting the snippet and not introduce any new API. OTOH the question may be fundamental enough to warrant a dedicated API one way or the other. |
The thing is, that from within pyplot, you don't have |
|
Yes, but they want a figure so creating one is fine. |
|
Yes, but there should be a side-effect free way of checking if an Axes exists. Ah, that said: |
Good catch, now fixed. |
|
See #20783 for the "let's just document already existing functionality" approach. |
This provides a relatively more user-friendly way to check whether a current figure/axes exists. (`_pylab_helpers.Gcf.get_active` is way too "internal".)
|
Closing in favor of #20783 (I think the docs improvement is actually better than expanding the API), though if anyone wants to champion this patch, feel free to pick it up. |
This provides a relatively more user-friendly way to check whether a
current figure/axes exists. (
_pylab_helpers.Gcf.get_activeis way too"internal".)
Inspired by #20770. I'm not particularly wedded to the kwarg name, better suggestions are welcome.
PR Summary
PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsand 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).