Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotting 3D surface using python: raise ValueError("Argument Z must be 2-dimensional.") matplotlib [duplicate]

I'm trying to plot a 3d surface passes through a set of (X,Y,Z) 3d point and I got raise ValueError("Argument Z must be 2-dimensional.") matplotlib

points = Tail_geo(D,L) # is a list from a function 
points = points + Nose_geo(D,L)# is a list from both function s
X = [x[0] for x in points]# seperate X from the list
Y = [x[1] for x in points]
Z = [x[2] for x in points]
X = np.asarray(X)
Y = np.asarray(Y)
Z = np.asarray(Z)
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, linewidth=0, antialiased=False)
plt . show ( )
like image 320
Ibrahim zawra Avatar asked Jul 28 '18 20:07

Ibrahim zawra


1 Answers

The function plot_surface expects its inputs to be structured as a regular 2D grid. For your data (x,y,z as lists) it would probably be more appropriate to use the plot_trisurf function. Just make a simple replacement in your code.

surf = ax.plot_trisurf(X, Y, Z, linewidth=0, antialiased=False)

There is a nice example in the matplotlib gallery here https://matplotlib.org/examples/mplot3d/trisurf3d_demo.html which you can look through for some more details.

like image 54
dtward Avatar answered Sep 18 '22 18:09

dtward