如何将2D等高线图定位到3D图中

时间:2018-12-14 16:52:04

标签: python 3d 2d contour

Im使用此代码对X,Y,Z数据进行轮廓处理。有什么方法可以在3d视图上定位2d轮廓,以便分析将来在同一3d上的不同2d轮廓图上绘制的数据。

from scipy.interpolate import griddata 
import numpy as np 
import matplotlib.pyplot as plt 


M = np.array([[0.000000,1217.000000,594.503284],
    [4.500000,1183.886353,2099.999905],
    [9.000000,1220.000000,1071.599126],
    [13.500000,1184.565430,2099.999905],
    [18.000000,1219.000000,435.631812],
    [22.500000,1185.150635,2099.999905],
    [24.500000,1217.555542,320.541441],
    [27.000000,1185.427490,2099.999905],
    [31.500000,1216.000000,300.000012],
    [36.000000,1185.981445,2099.999905],
    [40.500000,1215.000000,306.778669],
    [45.000000,1186.629272,2099.999905],
    [49.500000,1216.000000,300.000012],
    [54.000000,1187.214478,2099.999905],
    [58.500000,1215.000000,300.000012],
    [63.000000,1187.893555,2099.999905],
    [67.500000,1218.000000,335.902870],
    [72.000000,1188.572510,2099.999905],
    [76.500000,1220.000000,359.615386],
    [81.000000,1189.282715,2099.999905],
    [85.500000,1224.000000,1382.480264],
    [90.000000,1189.992920,2099.999905],
    [94.500000,1225.000000,1206.023455],
    [99.000000,1190.578125,2099.999905]])

    #upper,limit
h = np.array([[0.0,1217],
    [4.5,1217],
    [9.0,1220],
    [13.5,1219],
    [18.0,1219],
    [22.5,1218],
    [27.0,1217],
    [31.5,1216],
    [36.0,1215],
    [40.5,1215],
    [45.0,1216],
    [49.5,1216],
    [54.0,1215],
    [58.5,1215],
    [63.0,1217],
    [67.5,1218],
    [72.0,1219],
    [76.5,1220],
    [81.0,1222],
    [85.5,1224],
    [90.0,1225],
    [94.5,1225],
    [99.0,1224],
    [103.5,1225]])
##
x=M[:,0] 
y=M[:,1]
z=M[:,2]
##  

xi=np.linspace(0,100.,100.) 
yi=np.linspace(1190,1225.,1225.) 
X,Y= np.meshgrid(xi,yi) 
Z = griddata((x, y), z, (X, Y),method='cubic') 

x0 = 0
dx = 4.5
for n1, xv in enumerate( X):
    for n2, x in enumerate( xv):
        index = (x - x0) / dx
        i1, i0 = int(np.ceil( index)), int(np.floor( index))
        y = (h[i1][1] - h[i0][1]) / dx * (x - h[i0][0]) + h[i0][1]
        if Y[n1][n2] > y:
            X[n1][n2] = np.nan
            Y[n1][n2] = np.nan
            Z[n1][n2] = np.nan

plt.contourf(X,Y,Z)
plt.colorbar()
plt.plot(h[:,0],h[:,1],'black',linewidth=2)
plt.scatter(x,y,marker ='o',c='k',s=10,zorder=10)
plt.xlim(0,100)
plt.ylim(1190,1225)
plt.grid(True)
plt.rc('grid',linestyle="-",color='black')
plt.show()

该想法是能够在3d视图中定位该2d轮廓,以便在同一3d图形中交叉不同的2d轮廓(如图b所示)。

0 个答案:

没有答案