I'm trying to plot 3 planes in 3D space using plotly, I can only define a surface along the XY plane, whilst ZY and XZ do not appear.
I'm including a simple example below, I would expect the code to produce three planes intersecting at the point (1, 1, 1), instead there is only one surface at (x, y) = 1.
Any help would be greatly appreciated.
import plotly.graph_objects as go
import numpy as np
zsurf = go.Surface(y=[0, 1, 2], x=[0, 1, 2], z=np.ones((3, 3)))
ysurf = go.Surface(x=[0, 1, 2], z=[0, 1, 2], y=np.ones((3, 3)))
xsurf = go.Surface(z=[0, 1, 2], y=[0, 1, 2], x=np.ones((3, 3)))
fig = go.Figure()
fig.add_trace(zsurf)
fig.add_trace(ysurf)
fig.add_trace(xsurf)
fig.show()
All of your x, y, z should have the same shape.
I don't because of which default UB one of your plane even show. But none of them are correctly specified.
What you meant is
import plotly.graph_objects as go
import numpy as np
xx,yy=np.meshgrid([0,1,2], [0,1,2])
zsurf = go.Surface(y=xx, x=yy, z=np.ones((3, 3)))
ysurf = go.Surface(x=xx, z=yy, y=np.ones((3, 3)))
xsurf = go.Surface(z=xx, y=yy, x=np.ones((3, 3)))
fig = go.Figure()
fig.add_trace(zsurf)
fig.add_trace(ysurf)
fig.add_trace(xsurf)
fig.show()
A surface (from plotly Surface point of view) is a 2D mesh of points in space. So a 2D array of points. That is 3 2D arrays, one for x, one for y, one for z. Each point being located in space
Or, to be more explicit (it is exactly the same as my first answer. Just, the mesh looks less magic when written explicitly rather that with meshgrid
)
import plotly.graph_objects as go
import numpy as np
zsurf = go.Surface(y=[[0,1,2],[0,1,2],[0,1,2]], x=[[0,0,0],[1,1,1],[2,2,2]], z=np.ones((3, 3)))
ysurf = go.Surface(x=[[0,1,2],[0,1,2],[0,1,2]], z=[[0,0,0],[1,1,1],[2,2,2]], y=np.ones((3, 3)))
xsurf = go.Surface(z=[[0,1,2],[0,1,2],[0,1,2]], y=[[0,0,0],[1,1,1],[2,2,2]], x=np.ones((3, 3)))
fig = go.Figure()
fig.add_trace(zsurf)
fig.add_trace(ysurf)
fig.add_trace(xsurf)
fig.show()