以下是我的功能:
def draw3D(draw_tick, matrixArray):
print "Drawing tick = %d\n" % draw_tick
matrix = matrixArray[draw_tick - 450]
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-40, 40, 1)
Y = np.arange(-40, 40, 1)
X, Y = np.meshgrid(X, Y)
Z = np.matrix[Y+40][X+40]
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,cmap=cm.coolwarm,linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
plt.close()
我想用变量 x,y,z 绘制一个 3D 图。
TypeError: 'type' object has no attribute '__getitem__'
此错误指向 Z 行:
Z = np.matrix[Y+40][X+40]
我想将该点(矩阵)的值存储到 Z
谁能帮我解决它?
非常感谢!
更新我的问题:我有一个包含数百个 81*81 矩阵的 matrixArray。我想在该数组中绘制一个矩阵的图。于是我宣布:
matrix= matrixArray[draw_tick - 450]
来决定具体的。然后我想将矩阵位置作为 X & Y,并将位置的值作为 Z。但我希望我的 X 和 Y 从 -40 到 +40,这就是为什么我在两个轴上加 40 .