Understanding how gratings work in plot_surface
is not easy. Therefore, I will first give a general explanation, and then I will explain how to convert the data to your case. If you have an array of N
x values โโand an array of M
y values, you need to create two grids of x and y values โโof dimension (M,N)
. Fortunately, numpy.meshgrid
will help. Embarrassed? Example:
x = np.arange(3) y=np.arange(1,5) X, Y = np.meshgrid(x,y)
The element (x[i], y[j])
is available as (X[j,i], Y[j,i])
. And its value Z
, of course, Z[j,i]
, which also needs to be determined.
Having said that, your data produces a surface point at (0,0,2)
, as expected. In fact, in this position there are two points coming from the coordinate indices (0,0,0)
and (1,1,1)
.
I am applying the result of building your arrays with:
fig = plt.figure() ax=fig.add_subplot(1,1,1, projection='3d') surf=ax.plot_surface(X, Y, Z)
