I have a Plotly Scatter3d() plot, and I want to draw lines between some of these. Physically speaking, I have a network where I have some nodes connected with bonds, and I want to draw these bonds. How do I go about it?
Scatter3d() comes with a mode='lines+markers' option that just makes it a point-and-line scatter plot, instead of the default point-only plot. That's not what I am looking for. I want to supply a list of pair of xyz coordinates, and I want a collection of lines at the end.
Here is my function for plotting a simple Scatter3d()plot:
def Splot3dPlotly(xyz):
'''
3D scatter plot using Plotly.
:param xyz: (NPx3) array of xyz positions
:return: A Plotly figure that can now be plotted as usual.
'''
xyz = np.reshape(xyz, (int(xyz.size/3), 3))
NN = int(sqrt(xyz.shape[0]))
trace1 = go.Scatter3d(
x=xyz[:,0],
y=xyz[:,1],
z=xyz[:,2],
mode = 'markers', # 'lines+markers',
marker=dict(color=range(NN*NN), colorscale='Portland')
)
data = [trace1]
layout = go.Layout(
margin=dict(
l=0,
r=0,
b=0,
t=0
)
)
fig = go.Figure(data=data, layout=layout)
return fig
