Because the examples given use x & y axis arrays with equal lengths and equal values, they do not bring out the fact that in z(i,j) i is the y axis & j is the x axis. If z.shape is (n,m) and you specify x= & y= arrays with with lengths n & m instead of m & n you still get a surface plot but not the one you want.
Yes, you are right! Thanks for pointing it out! Unfortunately an example typical for defining a surface of equation z=f(x,y), with x in [a,b], y in [c, d] is missing:
x = np.linspace(a, b, n) y = np.linspace(c, d, m) X, Y = np.meshgrid(x, y) #X, Y have shape(m, n) z = f(X, Y) #z of shape(m, n)
A concrete example that points out that this is the right definition is z= cos(x*y):
x = np.linspace(0, np.pi, 50) y = np.linspace(-np.pi/2, 0, 25) X, Y = np.meshgrid(x, y) z= np.cos(X*Y) fig = go.Figure(data=[go.Surface(z=z, x=x, y=y)]) fig.update_layout(width=500, height=500) print(x.shape, y.shape, z.shape) (50,) (25,) (25, 50)
Hence this tutorial example https://plotly.com/python/3d-surface-plots/#passing-x-and-y-data-to-3d-surface-plot should be updated as follows :
sh_0, sh_1 = z.shape x, y = np.linspace(0, 1, sh_1), np.linspace(0, 1, sh_0)