0
I’m trying to plot a graph in 3d. I already have in 2d. All quiet there.
It is a matrix with the values of the amplitudes of a wave propagating in a tab. But I would plot the values of the matrix as 'heights'.
In the code below, the dimensions of the original matrix are len(vals) = 333
and len(vals[2]) = 116
.
To the line that starts with surf = ax.plot_surface...
, the error that appears is as follows:
ValueError: Shape mismatch: objects cannot be broadcast to a single shape
xx, yy = np.mgrid[1:333, 1:116]
fig = plt.figure(figsize=(13,7))
ax = plt.axes(projection='3d')
surf = ax.plot_surface(xx, yy, vals2[100], rstride=1, cstride=1, cmap='RdBu', edgecolor='none')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('Intensity')
ax.set_title('Wave propagation inside waveguide')
fig.colorbar(surf, shrink=0.5, aspect=5) # add color bar
ax.view_init(60,35)
plt.savefig('figuraTeste3d.png', format='png')
plt.show()