Below is my fuction:
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()
I want to draw a 3D plot with variables x,y,z.
TypeError: 'type' object has no attribute '__getitem__'
This error points to the line of Z:
Z = np.matrix[Y+40][X+40]
I want to store the value of that point (of matrix) into Z
Can anyone help me to solve it?
Lots of thanks!
Update of my question: I have a matrixArray containing hundreds of matrices of 81*81. I want to draw a plot of one matrix in that array. So I declared:
matrix= matrixArray[draw_tick - 450]
to decide the particular one. Then I want to put the matrix location as X & Y, and put the value of the location as Z. But I want my X and Y be from -40 to +40, that is why I'm adding 40 to the two axis.
numpy.matrix is a class (and classes in Python are objects that are instances of
type
), and you are trying to access it as if it was a nested array. You probably want the value inmatrix
instead.