skymoon_fp
波那文都
2019-04-15 12:24

生成二维均匀分布的三维图报错AttributeError: 'int' object has no attribute 'ndim'?

  • python
  • 生成二维均匀分布的三维图报错

  • 代码如下:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')
x=np.arange(0,1,0.01)
y=np.arange(0,1,0.01)
X,Y=np.meshgrid(x,y)
Z1=1
Z2=0
surf=ax.plot_surface(X,Y,Z1,color='b')
surf=ax.plot_surface(X,Y,Z2,color='r')

plt.show()
  • 报错信息

Traceback (most recent call last):

File "二维均匀分布.py", line 15, in

surf=ax.plot_surface(X,Y,Z1,color='b')

File "E:\DataAnalysis\python-3.7.0\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 1610, in plot_surface

if Z.ndim != 2:

AttributeError: 'int' object has no attribute 'ndim'

  • 截图

图片说明

给底面Z=0和均匀分布的平面Z=1染色,但显示这个问题,搜索了下,基本上没有与这个相似的。。。请教该如何改啊!~

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答