python 检查图形是 2d 还是 3d

标签 python matplotlib figure axes

在带有图形的 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/

相关文章:

python - MD5 加密问题

python - 哪种稀疏矩阵格式更适合构建分块矩阵

r - R Markdown PDF 中图上方的图标题

python - 尝试向 Matplotlib 图表添加颜色渐变

matplotlib - 控制 pyplot 中 x 刻度的数量

layout - latex :文字不能放在图像下方

python - matplotlib 图中的链接时间轴(x 轴)

python - 当我有两个版本的 python 时,如何在 PyCharm 中更新 pip?

python - 如何在python中用增量计数替换数字字符串

python - 使用 slider 小部件以交互方式更改图像内容