ax.plot_surface(grid_x, grid_y, grid_z, facecolors=plt.cm.jet(grid_c), alpha=0.5)报错 Argument Z must be 2-dimensional.
时间: 2024-02-15 11:02:42 浏览: 132
这个错误提示是因为参数 Z 必须是一个二维数组,而你传入的 grid_z 可能是一个一维数组或者不是二维的二维数组。要解决这个问题,可以将 grid_z 转换成二维数组,例如通过 numpy 库的 reshape() 函数来实现:
```
import numpy as np
grid_z = np.reshape(grid_z, (len(grid_x), len(grid_y)))
ax.plot_surface(grid_x, grid_y, grid_z, facecolors=plt.cm.jet(grid_c), alpha=0.5)
```
这样就可以将 grid_z 转换成与 grid_x 和 grid_y 一样的二维数组,从而避免了 "Argument Z must be 2-dimensional" 的错误提示。
阅读全文