如何在python plot_surface中设置Z轴的比例等于X和Y轴 [英] how to set the scale of Z axis equal to X and Y axises in python plot_surface

查看:50
本文介绍了如何在python plot_surface中设置Z轴的比例等于X和Y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在matplotlib中使用plot_surface绘制3D曲面.我的代码是:

I tried use plot_surface in matplotlib to plot a 3D surface. My code is:

fig = plt.figure()
ax = fig.gca(projection='3d')
# ax.set_aspect('equal')
ax.plot_surface(X, Y, H4200, rstride=1000, cstride=1000)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
# ax._autoscaleXon = True
# ax._autoscaleYon = True
# ax._autoscaleZon = True
# ax.set_aspect('equal', adjustable='box')

plt.show()

情节的结果是:

1:

2:

显然,Z单位的长度不等于X和Y轴的单位.

obviously, the length of Z units is not equal to the units of X and Y axises.

我的问题是如何设置 Z 轴的刻度等于 X 和 Y 轴的刻度?

My question is how to set the scale of Z axis equal to the scale of X and Y axises?

我尝试了 ax.set_aspect('equal'),ax._autoscaleXon = True,ax._autoscaleYon = True,ax._autoscaleZon = True,ax.set_aspect('equal',Adjustable ='box')(如我的评论所示),但不起作用,如何解决此问题?我需要你的帮助,谢谢!

I tried ax.set_aspect('equal'), ax._autoscaleXon = True, ax._autoscaleYon = True, ax._autoscaleZon = True, ax.set_aspect('equal', adjustable='box') as seen in my comments, but it's not work, How can I do to resolve this question? I need your help, Thanks!

推荐答案

尝试

ax.set_aspect(1)

它对我有用.

编辑 1

在您的情况下,我怀疑 set_aspect(1) 或 set_aspect('equal') 失败,因为 matplotlib 强制自动缩放 z 轴以适应 z 数据的整个范围(与 x 和 y 的数量级不同).在这种情况下,您需要一些可用的技巧 此处.

In your case, I suspect that set_aspect(1) or set_aspect('equal') fails because matplotlib forces autoscale z axis to accommodate the whole range of your z data (with a different order of magnitude than x and y). In such situation, you need some tricks that are available here.

这篇关于如何在python plot_surface中设置Z轴的比例等于X和Y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆