I tried to do a 3D scatter plot with driplines and a projection onto the X-Y plane using Plotly Python. Could anyone tell me how to do this? Thanks!
HI @Bibu welcome to the forums.
Are you referring to something like this?
import plotly.graph_objects as go
fig = go.Figure(
data=go.Scatter3d(
x=[1,2,3],
y=[1,2,3],
z=[1,2,3],
mode='markers+lines',
projection={
'z':{'show':True}
}
)
)
fig.show()
mrep 3D
@Bibu
This is an example of 3d stem plot:
import numpy as np
import plotly.graph_objects as go
nx=5
ny=6
hmax=7
xl = np.linspace(2,18, nx)
yl= np.linspace(0, 14, ny)
x, y = np.meshgrid(xl,yl)
z= hmax*np.random.rand(nx*ny)
stemsx = []
stemsy = []
stemsz = []
for xs, ys in zip(x.flatten(), y.flatten()):
stemsx.extend([xs, xs, None])
stemsy.extend([ys, ys, None])
for zs in z:
stemsz.extend([0, zs, None])
fig= go.Figure(go.Scatter3d(x=stemsx, y=stemsy, z=stemsz, mode= "lines",
line_width=2, line_color="RoyalBlue"))
fig.add_trace(go.Scatter3d(x=x.flatten(), y=y.flatten(), z=z, mode="markers",
marker_size=5,
marker_color="RoyalBlue"))
fig.update_layout(
width=600, height=600,
scene_aspectmode="data", scene_camera_eye=dict(x=2, y=2, z=1),
showlegend=False)
2 Likes