In Python's matplotlib library it is easy to specify the projection of an axes object on creation:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
ax = plt.axes(projection='3d')
But how do I determine the projection of an existing axes object? There's no ax.get_projection
, ax.properties
contains no "projection" key, and a quick google search hasn't turned up anything useful.
It turns out that the answer given here is actually a better answer to this question: python check if figure is 2d or 3d And the answer i provided at that duplicate is a better answer to this question.
In any case, you can use the name
of the axes. This is the string that determines the projection.
plt.gca().name or ax.name
if ax
is the axes.
A 3D axes' name will be "3d"
. A 2D axes' name will be "rectilinear"
, "polar"
or some other name depending on the type of plot. Custom projections will have their custom names.
So instead of ax.get_projection()
just use ax.name
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With