我想繪製一個使用具有4列的數據的3D表面繪圖,即它將x,y,z,c。下面示出的數據 -用Python中的4個數組繪製3D表面圖
0.452 -172.799 -172.800 0.000000
0.452 -172.799 -158.400 -9.305322
0.452 -172.799 -144.000 -12.062071
0.452 -172.799 -129.600 -9.008698
0.452 -172.799 -115.200 -5.402975
0.452 -172.799 -100.800 -3.957608
0.452 -172.799 -86.400 -5.113347
0.452 -172.799 -72.000 -4.784993
0.452 -172.799 -57.600 -6.659095
0.452 -172.799 -43.200 -4.405937
0.452 -172.799 -28.800 -6.110385
0.452 -172.799 -14.400 -5.896424
0.452 -172.799 -0.001 -4.405937
0.452 -172.799 14.399 -6.489442
0.452 -172.799 28.799 -5.662057
0.452 -172.799 43.199 -7.710180
0.452 -172.799 57.599 -7.710180
0.452 -172.799 71.999 -8.011659
0.452 -172.799 86.399 -6.489442
0.452 -172.799 100.799 -6.817796
0.452 -172.799 115.199 -5.662057
0.452 -172.799 129.599 -5.402975
0.452 -172.799 143.999 -5.662057
0.452 -172.799 158.399 -3.957608
0.452 -172.799 172.799 -2.701488
0.615 -172.799 -172.800 -8.444175
0.615 -172.799 -158.400 -13.183417`
前三列代表在x,y,z和第四列c將是彩條即表面顏色將根據到c給出。
現在我已經嘗試了幾個簡單的代碼,但仍然出現錯誤。我嘗試了是 -
import pylab as p
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib.cm as cm
data = np.genfromtxt('test1.pmf')
x=data[:,1]
y=data[:,2]
h=data[:,3]
z=data[:,0]
datamin=min(h)
datamax=max(h)
fig=p.figure()
ax=fig.add_subplot(111, projection='3d')
pmf = ax.plot_surface(x, y, z, facecolors=cm.ocean(h))
p.colorbar(pmf)
p.show()
我得到了一個錯誤,如
pmf = ax.plot_surface(x, y, z, facecolors=cm.ocean(h))
File "/usr/lib/pymodules/python2.7/mpl_toolkits/mplot3/axes3d.py",line663,in
plot_surface rows, cols = Z.shape ValueError: need more than 1 value to unpack
任何想法,我做錯了在這?
非常感謝!
的'在您提供的不改變(第二列)的數據x'座標。你如何期望這是一個表面? – hitzg 2014-11-11 21:22:08