2016-11-07 414 views
1

我希望做一個類似於found here情節,與簡單的區別,我想從中心每個點設置的距離。也就是說,由於情節的一部分是一個圓圈,我希望每個點都離中心有一段可以確定的距離。Matplotlib:繪製二維數組徑向使3D散點圖

我一開始,考慮到前面提到的答案的簡單修改:

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib 
import numpy as np 
from scipy.interpolate import interp1d 
from matplotlib import cm 
from matplotlib import pyplot as plt 
step = 0.04 
maxval = 1.0 
fig = plt.figure() 
ax = Axes3D(fig) 
# u here would define the desired distance from radial axis 
# u=np.array([0,1,2,1,0,2,4,6,4,2,1]) 
v=np.array([4,4,6,3,6,4,1,4,4,4,4]) 
r=np.array([0,1,2,3,4,5,6,7,8,9,10]) 
f=interp1d(r,u) 

# walk along the circle 
p = np.linspace(0,2*np.pi,len(r)) 
R,P = np.meshgrid(r,p) 
# transform them to cartesian system 
X,Y = R*np.cos(P),R*np.sin(P) 

Z=f(R) 

ax.scatter(X, Y, Z)#, rstride=1, cstride=1, cmap=cm.jet) 
ax.set_xticks([]) 
fig.savefig(str(output_prefix + '3d..png'), dpi=(200)) 

enter image description here 我想什麼陰謀(對於模糊的草圖道歉): enter image description here

我嘗試使用interp2d來添加u變量註釋掉上面,但沒有運氣。更改Z到陣列u扔了錯誤的X,Y和Z必須是相同的尺寸("Argument 'zs' must be of same size as 'xs' ",可以理解爲X和Y現在插值)什麼是我需要做什麼?任何提示將不勝感激!

回答

0

我不知道你在你的問題的含義。 我把v作爲x軸圓心的偏移量。

from mpl_toolkits.mplot3d import Axes3D 
import numpy as np 
from scipy.interpolate import interp1d 
from matplotlib import pyplot as plt 
step = 0.04 
maxval = 1.0 
fig = plt.figure() 
ax = Axes3D(fig) 
# v here would define the desired distance from radial axis 
u=np.array([0,1,2,1,0,2,4,6,4,2,1]) 
v=np.array([4,4,6,3,6,4,1,4,4,4,4]) 
r=np.array([0,1,2,3,4,5,6,7,8,9,10]) 
f=interp1d(r,u) 

# walk along the circle 
V = np.tile(v, (len(u), 1)) 
p = np.linspace(0,2*np.pi,len(r)) 
R,P = np.meshgrid(r,p) 
# transform them to cartesian system 
X,Y = V + R*np.cos(P),R*np.sin(P) 

Z=f(R) 

ax.scatter(X, Y, Z)#, rstride=1, cstride=1, cmap=cm.jet) 
ax.set_xticks([]) 
plt.show()