2017-09-17 320 views
1

我試過在matplotlib中使用plot_surface繪製3D表面。我的代碼是:如何在python plot_surface中設置Z軸的刻度等於X和Y軸

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:

enter image description here

2:

enter image description here

明顯,Z的長度單位不等於X a的單位nd Y軸。

我的問題是如何設置Z軸的比例等於X軸和Y軸的比例?

我試過ax.set_aspect('equal'), ax._autoscaleXon = True, ax._autoscaleYon = True, ax._autoscaleZon = True, ax.set_aspect('equal', adjustable='box')在我的評論中看到,但這不是工作,我該怎麼辦才能解決這個問題?我需要你的幫助,謝謝!

回答

0

嘗試,

ax.set_aspect(1) 

這對我的作品。

編輯1

在你的情況下,我懷疑set_aspect(1)或set_aspect(「等於」)將失敗,因爲matplotlib力的自動縮放的z軸,以適應您ž數據的整個範圍(具有不同數量級比x和y)。 在這種情況下,您需要一些可用的技巧here

+0

我已經嘗試過,但它仍然不起作用 – yogazining

+0

@ yogazining請參閱我編輯的答案。 – swatchai

+0

非常感謝你,我已經實施你的解決方案,它的工作原理!大!! – yogazining