@@ -25,38 +25,47 @@ def add_parser(cls, parser):
2525 )
2626 parser .add_argument ("--start" , type = str , default = "2024-01-01" , help = "Display data after" )
2727 parser .add_argument ("--field" , type = str , help = "Single column to plot" )
28+ parser .add_argument ("--group" , action = "store_true" , help = "Group all lines onto a single plot" )
2829
2930 def __init__ (self , args ):
3031 self .files = args .files
3132 self .field = args .field
3233 self .start = args .start
34+ self .group = args .group
3335
3436 def run (self ):
3537 import pandas as pd
3638 import plotly .express as px
39+ import plotly .graph_objects as go
3740 from dash import Dash , dcc , html
3841
39- figures = []
42+ fig : None | go .Figure = None
43+ figures : list [dcc .Graph ] = []
44+ if self .group :
45+ fig = go .Figure ()
46+
4047 for file in self .files :
4148 df = pd .read_csv (file )
4249
4350 mask = df ["time" ] >= self .start
4451 filtered_df = df .loc [mask ]
4552
46- if self .field :
47- y_data = filtered_df [self .field ]
53+ y_data = filtered_df [self .field ] if self .field else filtered_df .columns .values [1 :]
54+ if self .group :
55+ assert fig is not None
56+ fig .add_trace (go .Scatter (x = filtered_df ["time" ], y = y_data , name = str (file .name ), mode = "lines" ))
4857 else :
49- y_data = filtered_df .columns .values [1 :]
50-
51- fig = px .line (
52- filtered_df ,
53- x = "time" ,
54- y = y_data ,
55- title = str (file ),
56- )
57- figures .append (dcc .Graph (figure = fig ))
58+ fig = px .line (
59+ filtered_df ,
60+ x = "time" ,
61+ y = y_data ,
62+ title = str (file ),
63+ )
64+ figures .append (dcc .Graph (figure = fig ))
5865
5966 app = Dash ()
67+ if self .group :
68+ figures = [dcc .Graph (figure = fig , style = {"height" : "90vh" })]
6069 app .layout = html .Div (figures )
6170
6271 app .run (debug = True )
0 commit comments