I have a nx3
array, lets call it data
, where I want the first 2 columns to be x
and y
coordinates and the 3rd column to be a z
coordinate associated with the x
and y
coordinates in the same row.
I now want to draw a surface plot where the surface intersects all the z
coordinates.
I have seen this post but cannot figure it out.
I know that I can use matplotlib's Axes3D
and fig.gca(projection='3d')
and that it takes 3 nxn
arrays, where I think the X
and Y
arrays can be obtained with X,Y = np.meshgrid(data[:,0],data[:,1])
, but I am not sure how to obtain an nxn
Z
array if there is only 1 Z
coordinate associated with each x
and y
.
Then, I would like to smoothen the surface, as I am sure a surface with only a few data points will look ugly, and I am only looking to represent the general shape of the data and specific values aren't too important. Thus, is there a way to interpolate between the data points in 2 dimensions to smoothen the graph?
Example data set:
data = np.array([[4260,150,116]
[4204,149,1070]
[4204,188,470]
[4444,140,389]
[3255,149,69]
[6370,149,1109]
[5765,189,3531]])
Try it like this:
x, y, z = data[:,0], data[:,1], data[:,2]
grid_x, grid_y = np.mgrid[min(x):max(x):50j, min(y):max(y):50j]
z = griddata((x, y), z, (grid_x, grid_y), method='cubic')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.