我有一个三维的numpy数据数组,以及三个相关的数组,给出每个点的极坐标。我想生成一个给定值的等值面 原始数组,并提取该表面上的点的r,theta和phi值。在2D中我做了这个(部分遵循这里给出的建议)如下所示(这也找到了假设为椭圆体数据的长轴和短轴之间的r的百分比差异),但是matplotlib函数轮廓不起作用3D。任何人都可以建议一种方法吗?
def ellipsecalc(divret2real,r,theta):
time_e1 = time.time()
plt.figure()
plt.contour(divret2real, [.8])
plt.show()
cs=plt.contour(divret2real, [.3])
p = cs.collections[0].get_paths()[0] # from matplotlib
v = p.vertices # interplated x,y positions of the contour
x = v[:,0]
y = v[:,1]
time_e2 = time.time()
print ('time for r at fixed plotting', time_e2 - time_e1, 'seconds')
rellipse = ndimage.map_coordinates(r, [[x],[y]], order=1)
thellipse = ndimage.map_coordinates(theta, [[x],[y]], order=1)
rellipse1d = rellipse.flatten()
thellipse1d = thellipse.flatten()
plt.figure()
plt.plot(thellipse1d, rellipse1d)
plt.show()
rellmax = np.amax(rellipse1d)
rellmin = np.amin(rellipse1d)
percrdiff = (((rellmax - rellmin)/2.) / ((rellmax + rellmin)/2.)) * 100.
rmaxref = np.argmax(rellipse1d)
thofrmax = thellipse1d[rmaxref]
print ('percentage difference, max and min axes', percrdiff)
time_e3 = time.time()
print ('time for r at fixed ac calc', time_e3 - time_e2, 'seconds')
return percrdiff, rellipse1d, thellipse1d, thofrmax