在带有图形的 matlab 中,检查它是 3D 图形还是 2D 图形,我使用:
V=axis;
并检查 V 的分量数量(2d 图为 4 个,3d 图为 6 个)。 我如何使用 python 和 matplotlib 实现这个?
最佳答案
您可以使用轴的名称
。
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.
You can therefore check
if ax.name == "3d":
# axes is 3D, do something
else:
# axes is not 3D, do something else
<小时/>
您还可以检查限制,如 the question this is a duplicate of 的答案中所建议的那样。 。这样你就可以得到限制
def get_limits(ax):
xlim = ax.get_xlim()
ylim = ax.get_ylim()
if hasattr(ax, 'get_zlim'):
zlim = ax.get_zlim()
return xlim, ylim, zlim
else:
return xlim, ylim
关于python 检查图形是 2d 还是 3d,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43563244/