每个因子/变量水平仅绘制/选择一个/第一个数据点

问题描述 投票:0回答:0

我有一个数据框

df2
,如下所示:

        Device  time    Path    variable    value
    0   A   2022-09-27 11:56:22.733740  C:\Users\Desktop\A_2022_09_27_11_56_22_,73.xls  V+  7.980062
    1   A   2022-09-27 11:56:22.733940  C:\Users\Desktop\A_2022_09_27_11_56_22_,73.xls  V+  7.982012
    (...)
    103 A   2022-09-27 11:56:22.733940  C:\Users\Desktop\A_2022_09_28_19_36_21_,71.xls  V+  7.982012
    (...)
    853 B   2022-09-27 11:56:22.734140  C:\Users\Desktop\B_2022_09_27_11_56_22_,73.xls  V+  7.983312

有了

Path
,我想只显示这些因素的第一个数据点。正如您所看到的,有几种设备可以提供多个数据帧。我想将所有这些单个数据框绘制在一个图中,但只有它们的第一个数据点和
Path
是或可以用作每个数据框的唯一指标。 这有可能吗?

以防万一,我稍后会在

plotly dash
环境中使用它,我将按如下方式设置情节:

dcc.Graph(id = 'General' 
            , figure={}
          ),
dcc.Checklist(
            id="signals",
            options = ['V+', 'V-', 'I_A', 'I_fil'],
            value = ['V+', 'V-'],
            inline=True
            ),
(...)
@app.callback(
              Output("General", "figure"), 
              Input("signals", "value")
              )

def update_line_chart(signals):

df2 = all_df.melt(id_vars=['Device','time', 'Path'], value_vars=['V+','V-','I_A', 'I_fil'])
df3 = df2[df2['variable'].isin(signals)]

fig_general = px.scatter(df3
                          , x = "time"
                          , y = 'value'
                          , color = 'Device'
                          , symbol = 'variable'
                          , hover_name = "Device"
                          , template = 'plotly_dark'
                          )
fig_general.update_layout(
                          transition_duration = 500
                          , autosize = True
                          , height = 700
                          )
fig_general.update_traces(marker_size = 6)
python plotly plotly-dash
© www.soinside.com 2019 - 2024. All rights reserved.