4

I would like to have more than just one 3d line in my graph to be able to compare the data unfortunately this .add_ methods are not present for all kinds of plots.

fig = px.line_3d(sample, x='Time', y='y' ,z='intensity')
# fig.add_line_3d(sample2, x='Time', y='y' ,z='intensity')
fig

Can I extract the traces from a figure and then plot them all together somehow?

enter image description here

1 Answer 1

5

With Plotly Express, you can create multiple lines with a single call, so long as your data is in a "tidy" format. You can use the color attribute to split your lines and color them differently, like this:

import pandas as pd

df = pd.DataFrame(dict(
    X=[0,1,2,3, 1,2,3,4], 
    Y=[0,2,3,1, 1,3,4,2], 
    Z=[0,3,1,2, 1,4,2,3],
    color=["a", "a", "a", "a", "b", "b", "b", "b"]
))

import plotly.express as px

fig = px.line_3d(df, x='X', y='Y', z='Z', color="color")
fig.show()

enter image description here

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

1 Comment

What if some lines need the same color but need to be split? (Without doing an explicit for-loop.)

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.