You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gca(projection="rectilinear") fails to reset projection on axes #10700
shows a warning and replaces the originally created polar axes by a lambert axes (not sure what behavior we actually want this to have once axes-collision detection in add_axes is removed).
However, in
We need to figure out exactly what gca is supposed to do, with or without kwargs. Suggestion:
If the current Axes exists and matches the kwargs (if any), return it.
If the current Axes exists and doesn't match the request, raise an Exception.
Otherwise, make a new Axes as requested.
Note: All this is in the pyplot context, where there can be many Axes, Figures, and Images, but for each of these categories there is a single current one.
In my suggestion, gca would not search through existing Axes--it would only check to see if it can use the current one. It would never modify or delete the current Axes.
I think that part of the problem we are running into is confusion between gca as a user-level pyplot command, and our use of gca inside pyplot functions, like polar. Functions like gca and polar should be simple--they were supposed to be designed for casual users and quick use. We need to lay out the simple scenarios for their use, and construct and document them accordingly.
If such a scenario includes gca(); polar(r, theta); then the logic for replacing the current rectilinear Axes with a polar Axes can reside in polar, without complicating gca.
I agree with @efiring's suggestion. In my interpretation, the main purpose is "getting the current axes" as the name says - no arguments required. As a fallback, if no axes exists, one is created which may need the parameters "get the current axes with these parameters".
For a sane API plt.gca(projection="rectilinear") must always result in a rectilinear axes and not change the current axes. Otherwise it should fail with an exception.
If a function like polar needs a certain projection it has to care for that itself.
Why exactly do you think a clean gca is not feasible?
(fwiw I don't actually really care about what the exact semantics of gca() are (I don't ever use it, after all :-)), other that they should be reasonably consistent... additional points if it allows us to get rid of (parts of) the internal AxesStack object, which seems to try to do too much IMO)
Looking at this again I wonder whether the simple solution is not just to deprecate all kwargs to gca() (one can instead call plt.subplot(**kwargs) to create a new subplot) and restrict gca() to, well, returning the current axes and do nothing else.
Agreed, that plt.gca() should not be used to create complex axes, so kwargs should be deprecated.
I would still allow a bare plt.gca() to create a default figure/axes if none exists. That's in the spirit of pyplot: A figure and axes are automatically created if necessary.
Activity
efiring commentedon Mar 7, 2018
We need to figure out exactly what
gcais supposed to do, with or without kwargs. Suggestion:Note: All this is in the pyplot context, where there can be many Axes, Figures, and Images, but for each of these categories there is a single current one.
In my suggestion, gca would not search through existing Axes--it would only check to see if it can use the current one. It would never modify or delete the current Axes.
I think that part of the problem we are running into is confusion between gca as a user-level pyplot command, and our use of gca inside pyplot functions, like polar. Functions like gca and polar should be simple--they were supposed to be designed for casual users and quick use. We need to lay out the simple scenarios for their use, and construct and document them accordingly.
If such a scenario includes
gca(); polar(r, theta);then the logic for replacing the current rectilinear Axes with a polar Axes can reside inpolar, without complicatinggca.efiring commentedon Mar 7, 2018
Addendum: Looking at some code, I suspect my precise suggestion is not feasible (can't get there from here), but the basic points remain.
timhoffm commentedon Apr 4, 2018
I agree with @efiring's suggestion. In my interpretation, the main purpose is "getting the current axes" as the name says - no arguments required. As a fallback, if no axes exists, one is created which may need the parameters "get the current axes with these parameters".
For a sane API
plt.gca(projection="rectilinear")must always result in a rectilinear axes and not change the current axes. Otherwise it should fail with an exception.If a function like
polarneeds a certain projection it has to care for that itself.Why exactly do you think a clean
gcais not feasible?anntzer commentedon Apr 4, 2018
(fwiw I don't actually really care about what the exact semantics of
gca()are (I don't ever use it, after all :-)), other that they should be reasonably consistent... additional points if it allows us to get rid of (parts of) the internal AxesStack object, which seems to try to do too much IMO)anntzer commentedon Dec 24, 2019
Looking at this again I wonder whether the simple solution is not just to deprecate all kwargs to gca() (one can instead call
plt.subplot(**kwargs)to create a new subplot) and restrict gca() to, well, returning the current axes and do nothing else.timhoffm commentedon Dec 25, 2019
Agreed, that
plt.gca()should not be used to create complex axes, so kwargs should be deprecated.I would still allow a bare
plt.gca()to create a default figure/axes if none exists. That's in the spirit ofpyplot: A figure and axes are automatically created if necessary.anntzer commentedon Dec 25, 2019
Yes, gca() should still create an axes if none exists.
FIX: restore creating new axes via plt.subplot with different kwargs
FIX: restore creating new axes via plt.subplot with different kwargs
FIX: restore creating new axes via plt.subplot with different kwargs
FIX: restore creating new axes via plt.subplot with different kwargs
FIX: restore creating new axes via plt.subplot with different kwargs
FIX: restore creating new axes via plt.subplot with different kwargs