5

I want to draw a line between two points in a 3D plot. But, I can not use plotly.express for some reasons as suggested in the documentation. https://plotly.com/python/3d-line-plots/

Is it possible to draw a line in a 3D plot using the plotly.graph_objects module ? If so, how ?

1 Answer 1

11

I found this solution:

plotly.express solution:

import plotly.express as px
import numpy as np 

x = np.array([0,1])
y = np.array([1,1])
z = np.array([1,1])
df = pd.DataFrame({"x": x, "y":y, "z":z})

fig = px.line_3d(df, x="x", y="y", z="z")
fig.show()

output :

output1

plotly.graph_objects version :

import plotly.graph_objs as go
import numpy as np 

x = np.array([0,1])
y = np.array([1,1])
z = np.array([1,1])

fig = go.Figure(data=go.Scatter3d(x=x, y=y,z=z, mode='lines'))
fig.show() 

output 2:

output2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.