簡體   English   中英

將 Plotly Express 跟蹤添加到具有多個跟蹤的圖形對象 go.Figure()?

[英]Add a Plotly Express trace to a Graph Objects go.Figure() with multiple traces?

我正在嘗試使用 plotly 圖形對象來可視化來自不同 pandas 數據幀的時間戳。 在成功添加軌跡為 go.Scatter() 圖后,我現在想添加一個 px.timeline() plot 作為軌跡。 這一般可以嗎?

這是我的代碼:

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go


df=pd.read_json(file1.json)
df2=pd.read_json(file2.json)
df3=pd.read_json(file3.json)

fig = go.Figure(layout=layout)
fig.add_trace(
    go.Scatter(x=df.column1, y=df.column2, name='name1', mode='markers')
)
fig.add_trace(
    go.Scatter(x=df2.column1, y=df2.column2, name='name2', mode='markers')
)
fig.add_trace(
    go.Scatter(x=df3.column1, y=df3.column2, name='name3', mode='markers')
)
#### add px trace ###
fig.update_traces(marker_size=10)

fig.show()

到目前為止,這運作良好。 現在,我想將 px.timeline() plot 作為跟蹤添加到我的圖中。 我試過了:

fig.add_trace(
    px.timeline(df,x_start="column1",
                x_end="column2", y='column3')

這會引發值錯誤:

ValueError: 
    Invalid element(s) received for the 'data' property of [...]

是否有將 px.-Plots 添加到 go.Figure() 的解決方法?

嘗試包括.data[0]

fig.add_trace(
px.timeline(df,x_start="column1",
            x_end="column2", y='column3').data[0])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM