1

我有一个三维 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
4

0 回答 0