對於我的生活,我無法弄清楚如何得到與this相同的結果。matplotlib顏色以3D繪圖從x,y,z數據集中不使用輪廓
該鏈接生成彩色3d圖而不使用輪廓。如果我使用相同的技術,但使用我自己的x,y,z數據集,我只能得到一種顏色。
差異必須以我爲圖形生成z數據的方式進行。
無論如何,使用該:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.mlab import griddata
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
import sys
def xyz_ret(file):
f = open(file, 'r')
xyz = []
for i in f:
ret = i.replace('\n','')
xyz.append(map(float,(ret.split('\t'))))
xyz = np.array(xyz)
return xyz[:,0],xyz[:,1],xyz[:,2]
x,y,z = xyz_ret('300.txt')
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
xi = np.linspace(min(x), max(x))
yi = np.linspace(min(y), max(y))
X, Y = np.meshgrid(xi, yi)
Z = griddata(x, y, z, xi, yi)
surf = ax.plot_surface(X, Y, Z, rstride=6, cstride=6, cmap=cm.jet,
linewidth=0)
ax.set_zlim3d(min(z), max(z))
ax.w_zaxis.set_major_locator(LinearLocator(10))
ax.w_zaxis.set_major_formatter(FormatStrFormatter('%.03f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
數據組:
-2187.99902 9380.009151 0.0209
-2187.00111 2474.994061 0.022
-10755.98931 6119.598968 0.0296
-5781.347693 609.427388 0.0301
-8761.562524 1942.391853 0.0285
-5695.576244 1894.624701 0.0251
-3801.215106 1096.153308 0.0257
-1616.821487 2452.940102 0.0182
-5790.547537 2975.622971 0.022
-8095.18467 4074.330871 0.0208
-9997.367785 2771.330212 0.0264
-10547.5635 4397.127096 0.0251
-5781.706776 3984.545588 0.0191
-3346.855289 4347.670408 0.0172
-918.639762 4518.515925 0.0142
-892.428381 5850.710005 0.0143
-5844.499993 6516.904257 0.0204
-10877.96951 6015.755723 0.0265
-10813.37291 7704.306099 0.0302
-7991.878303 7733.626264 0.0223
-5861.073574 8725.943697 0.0217
-3188.107715 6997.19893 0.0206
-897.427629 7474.426336 0.0188
-1388.841321 8786.642046 0.0194
-3370.72325 8825.154803 0.0225
-8561.226722 8851.111988 0.0285
-10275.58972 8849.798032 0.0341
-5853.645621 10113.77051 0.0255
-8101.002878 10754.8429 0.0332
-5765.080546 11378.95524 0.0299
-3081.969839 10549.46676 0.0242
只有一種顏色被示出。另請注意,顏色欄沒有刻度。
你能解釋我的問題是什麼嗎?
我會說你沒有使用Axes3D.plot_surface。您導入Axes3D,但不使用它。 – joaquin 2010-12-06 07:18:47
它在ax = fig.add_subplot(111,projection ='3d')中使用,如果我刪除Axes3d,腳本將在該行發生錯誤。 – hl3fx 2010-12-06 09:26:42