Memory efficient way of plotting several line segements in Plotly?

Viewed 27

I have a collection of timestamps that correspond roughly to the time these modules called "metal cells" are being utilized. At present, I am grabbing these by pairs and plotting them by creating a small line segment using go.Scatter and adding it to a list which later functions as the data argument for a go.Figure object.

for mcell in metal_cells:
    mdf = cell_dep_grouped.get_group(mcell).reset_index(drop=True)
    
    for i in range(0, mdf.shape[0], 2):
        
        start_row = mdf.iloc[i]
        finish_row = mdf.iloc[i+1]
    
        buffer_dat = go.Scatter(x = [start_row.Time, finish_row.Time], 
                                   y = [mcell, mcell], 
                                   line = {'color': chem_palette[start_row.Recipe]},
                                   legendgroup = start_row.Recipe, 
                                   name = start_row.Recipe, 
                                   showlegend = not plotted_chem[start_row.Recipe])
        plot_data.append(buffer_dat)

The output looks as the picture I have attached, and I would like it to continue looking as closely to it because it clearly highlights the time the module was being utilized using the scatter segments, and downtime as implied by the empty space between segments. The main issue is I need this plot to be interactive - the main interactive feature being that, upon performing a selection, some calculations are made and some of the traces change. But because the plot consists of 80 or so go.Scatter objects, it is quite slow. Is there a more efficient way of plotting segments like these that make the plot lighter and faster?

Current graphic

0 Answers
Related