我尝试使用 matplotlib 中的plot_surface 来绘制 3D 曲面。我的代码是:
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轴单位的长度。
我的问题是如何将Z轴的比例设置为等于X和Y轴的比例?
I tried ax.set_aspect('equal'), ax._autoscaleXon = True, ax._autoscaleYon = True, ax._autoscaleZon = True, ax.set_aspect('equal', adjustable='box')
正如我的评论中所见,但这不起作用,我该如何解决这个问题?我需要你的帮助,谢谢!
Try,
ax.set_aspect(1)
这个对我有用。
Edit 1
在您的情况下,我怀疑 set_aspect(1) 或 set_aspect('equal') 失败,因为 matplotlib 强制自动缩放 z 轴以适应 z 数据的整个范围(与 x 和 y 的数量级不同)。
在这种情况下,你需要一些可用的技巧here https://stackoverflow.com/questions/13685386/matplotlib-equal-unit-length-with-equal-aspect-ratio-z-axis-is-not-equal-to.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)