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
[Doc]: How to replicate behaviour of plt.gca(projection=...)? #20770
I guess you are looking for is something like if plt.get_fignums() and plt.gcf().axes? (get_fignums() will tell you if there's any pyplot figures around, and if there's one around you want to check if they already have any axes)
OK, this was #19153 and had a pretty long deprecation message, if I understand correctly. Was the deprecation message not showing up for plt.gca()?
@dsantsby, can you explain more your use case here? I guess I can see that one might organize one's axes this way, but it seems very ad-hoc to create a new polar axes unless one already exists, and in that case use the existing axes. Over all we are really trying to move away from state-based thinking, and this is a pretty extreme example.
The deprecation message is showing up for plt.gca(), but it doesn't explain how to replicate the behaviour of plt.gca(projection=...). I've copied the message at the bottom of this comment.
My use case is a plot method in another library, which when called with no specified Axes I want to:
Get the current axes
If these are polar, use these axes
If not, raise an error
If no current axes are present, create a new polar axes
The reason I can't use plt.gca() for step one is it will create a new Axes with a non-polar projection, and it's not then possible to change the projection after creating the Axes. #20773 seems to fix this.
Over all we are really trying to move away from state-based thinking, and this is a pretty extreme example.
This is fair, but there's nothing in the what's new changelog entry explaining this or discouraging users. So I think there should either be a clear explanation to this effect explaining why plt.gca(projection=...) is discouraged, or some clear instructions on how to replicate the behaviour of plt.gca(projection=...).
matplotlib._api.deprecation.MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
@dstansby I'll close this, as #20773 was superseded by #20783 which should(?) be sufficient and has been merged, but feel free to reopen or PR more docs if you disagree.
Activity
anntzer commentedon Jul 31, 2021
I guess you are looking for is something like
if plt.get_fignums() and plt.gcf().axes? (get_fignums()will tell you if there's any pyplot figures around, and if there's one around you want to check if they already have any axes)jklymak commentedon Jul 31, 2021
Do we remember when this came in. I'm pretty sure we discussed this issue.
jklymak commentedon Aug 1, 2021
OK, this was #19153 and had a pretty long deprecation message, if I understand correctly. Was the deprecation message not showing up for
plt.gca()?@dsantsby, can you explain more your use case here? I guess I can see that one might organize one's axes this way, but it seems very ad-hoc to create a new polar axes unless one already exists, and in that case use the existing axes. Over all we are really trying to move away from state-based thinking, and this is a pretty extreme example.
dstansby commentedon Aug 1, 2021
The deprecation message is showing up for
plt.gca(), but it doesn't explain how to replicate the behaviour ofplt.gca(projection=...). I've copied the message at the bottom of this comment.My use case is a plot method in another library, which when called with no specified Axes I want to:
The reason I can't use
plt.gca()for step one is it will create a new Axes with a non-polar projection, and it's not then possible to change the projection after creating the Axes. #20773 seems to fix this.This is fair, but there's nothing in the what's new changelog entry explaining this or discouraging users. So I think there should either be a clear explanation to this effect explaining why
plt.gca(projection=...)is discouraged, or some clear instructions on how to replicate the behaviour ofplt.gca(projection=...).anntzer commentedon Sep 2, 2021
@dstansby I'll close this, as #20773 was superseded by #20783 which should(?) be sufficient and has been merged, but feel free to reopen or PR more docs if you disagree.
call_python_client: Use newer matplotlib API for 3d plotting
call_python_client: Use newer matplotlib API for 3d plotting
Fix for gca not accepting kwargs
call_python_client: Use newer matplotlib API for 3d plotting (#17938)
Fix for gca not accepting kwargs