How to plot multiple 3d lines with plotly express?

最后都变了- 提交于 2020-06-17 14:48:09

问题


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?


回答1:


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()



来源:https://stackoverflow.com/questions/58034958/how-to-plot-multiple-3d-lines-with-plotly-express

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!