简体   繁体   中英

How to plot a 3D surface Plot using three 1D arrays in python as I am getting an error Z must be in 2 dimensional. How to convert it into 2D array?

With three random 1D arrays I am trying to create a surface Plot

`
Z = [7.209, 7.223, 7.229, 7.236, 7.243, 7.27, 7.277, 7.284, 7.292, 7.306,
     7.312, 7.329, 7.337, 7.347, 7.354, 8.356, 8.363, 8.374, 8.39, 8.398]
X = np.random.rand(20)
Y = np.random.rand(20)
X, Y = np.meshgrid(X,Y)
ax.plot_surface(X,Y,Z,rstride=4,cstride=4, cmap=plt.cm.coolwarm)
`

I am getting an error

    if Z.ndim != 2:
AttributeError: 'list' object has no attribute 'ndim'

How to plot a 3D surface plot with the Z values not being a function of X and Y.

There is no connection between the points. They are 3 independant 1D arrays with X having 20 points, Y having 20 points and Z having 20 points. The only reason I did a meshgrid is to convert the 1D array into 2D array which is the requirement to plot the surface plot and I am not getting how to plot the Z values on that meshgrid of X and Y.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM