@@ -164,42 +164,23 @@ def plot_interactive_spectra(
164164            dict (type = "line" , xref = "paper" , x0 = 0 , x1 = 1 , yref = "y" , y0 = yh , y1 = yh , line = dict (color = "red" , dash = "dash" ))
165165        )
166166
167-     # Create frames for each index 
168-     slider_index  =  list (range (len (spectra [0 ])))
167+     # Create initial figure 
169168    fig  =  go .Figure ()
170169
171170    # Build initial figure for immediate display 
172-     init_idx  =  slider_index [ 0 ] 
171+     init_idx  =  0 
173172    for  i , spec  in  enumerate (spectra ):
174173        fig .add_trace (go .Scatter (x = wavelengths , y = spec [init_idx ], mode = "lines" , name = spectrum_labels [i ]))
175-     # Build frames for animation 
176-     frames  =  []
177-     for  idx  in  slider_index :
178-         frame_data  =  []
179-         for  i , spec  in  enumerate (spectra ):
180-             frame_data .append (go .Scatter (x = wavelengths , y = spec [idx ], mode = "lines" , name = spectrum_labels [i ]))
181-         frames .append (
182-             go .Frame (
183-                 data = frame_data ,
184-                 name = str (idx ),
185-             )
186-         )
187174
188-     fig .frames  =  frames 
189- 
190-     #  Create transition steps 
175+     # Create transition steps 
191176    steps  =  []
192-     for  idx  in  slider_index :
193-         steps .append (
194-             dict (
195-                 method = "animate" ,
196-                 args = [
197-                     [str (idx )],
198-                     {"mode" : "immediate" , "frame" : {"duration" : 0 , "redraw" : True }, "transition" : {"duration" : 0 }},
199-                 ],
200-                 label = str (idx ),
201-             )
177+     for  idx  in  range (len (spectra [0 ])):
178+         step  =  dict (
179+             method = "restyle" ,
180+             args = ["y" , [spec [idx ] for  spec  in  spectra ]],
181+             label = str (idx ),
202182        )
183+         steps .append (step )
203184
204185    # Create the slider 
205186    sliders  =  [dict (active = 0 , currentvalue = {"prefix" : "Index: " }, pad = {"t" : 50 }, steps = steps )]
0 commit comments