python检查数字是2d还是3d

python检查数字是2d还是3d

本文介绍了python检查数字是2d还是3d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在带有图形的matlab中,要检查它是3D图形还是2D图形,我使用:

In matlab with a figure, to check if it is 3D figure or 2D figure I use:

V=axis;

,然后检查V的分量数(2d图形为4,3d图形为6).我该如何使用python和matplotlib来实现这一点?

and check the number of components of V (4 for 2d figure, 6 for 3d figure).How can i implement this with python and matplotlib?

推荐答案

您可以使用轴的name.

plt.gca().name   or   ax.name

如果ax是轴.

3D轴的名称为"3d". 2D轴的名称将为"rectilinear""polar"或其他名称,具体取决于绘图的类型.

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.

因此您可以检查

if  ax.name == "3d":
    # axes is 3D, do something
else:
    # axes is not 3D, do something else


您还可以根据对.这样,您将获得极限


You can also check for the limits, as proposed in an answer to the question this is a duplicate of. In this way you would get the limits

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 00:15