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 ( )
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With