0
我想繪製常規網格。我使用了plot_surface,但結果有點奇怪。你能幫忙畫畫嗎?我試圖改變軸的限制,但它沒有幫助。可能是你可以建議更好的方式來繪製點作爲表面。謝謝!在Python中繪製表面
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
from array import *
x = np.array([0, 0, 0, 400, 400, 400, 800, 800, 800])
y = np.array([0, 400, 800, 0, 400, 800, 0, 400, 800])
z = np.array([10.0, 10.0, 10.0, 10.0, 206.8, 10.0, 10.0, 10.0, 10.0])
#print len(x), len(y), len(z)
zdict = {}
for i in range (0, len(x)):
#print "(", x[i], ", ", y[i], "): ", z[i], ", "
zdict[(x[i], y[i])] = z[i]
print zdict
def zfunc(x, y):
return zdict[(x, y)]
X, Y = np.meshgrid(x, y)
print X, Y
#need 2d array of Z
Z = [[zfunc(X[i][j], Y[i][j]) for i in range(0, len(X))] for j in range(0, len(X[0]))]
print Z
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(0, 300.0)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
你可以附上你的輸出圖片和你認爲是錯誤的嗎? – cfh
@cfh [鏈接](http://s020.radikal.ru/i710/1505/13/19f0f4ff2c0e.png)它看起來不像一個表面 – Vladimir