Python 从三维等高线中提取数据
我有一个三维numpy数据数组,以及三个关联的数组,给出每个点的极坐标。我想生成一个给定值的等值面 原始数组,并提取该曲面上点的r、θ和φ值。在2D中,我这样做了(部分遵循此处的建议),如下所示(这也发现了假定为椭球体数据的长轴和短轴之间r的百分比差异),但matplotlib函数轮廓在3D中不起作用。有人能建议一种方法吗 def ellipsecalc(divret2real,r,θ):Python 从三维等高线中提取数据,python,3d,Python,3d,我有一个三维numpy数据数组,以及三个关联的数组,给出每个点的极坐标。我想生成一个给定值的等值面 原始数组,并提取该曲面上点的r、θ和φ值。在2D中,我这样做了(部分遵循此处的建议),如下所示(这也发现了假定为椭球体数据的长轴和短轴之间r的百分比差异),但matplotlib函数轮廓在3D中不起作用。有人能建议一种方法吗 def ellipsecalc(divret2real,r,θ): 你能为你在上面使用的语言添加一个标签吗?matlab还是什么? time_e1 = time.time()
你能为你在上面使用的语言添加一个标签吗?matlab还是什么?
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