Dinamically changing plots

I’m trying to make a dinamic plot. My initial code to create the plot is the following:

p = figure(title="Total Incidents", x_axis_label='Date', y_axis_label='Incidents',x_axis_type='datetime',width=1200, height=500)
start_time=time.time()
p.varea_stack(list(map(str,unique_values)),x="x_values",  source=source, color=magma(len(unique_values)))
print(time.time()-start_time)

This works fine even if the plot generates a list[GlyphRenderer] of length 200.
The time spent is: 0.15152668952941895
My goal is being able to update the plot. My current code inside a callback is the following:

data,unique_values=update(freq,group)
source.data =data
p.renderers=[]
start_time=time.time()
p.varea_stack(list(map(str,unique_values)),x="x_values",  source=source, color=magma(len(unique_values)))
print(time.time()-start_time)

It works but if the list[GlyphRenderer] length is elevated(I’m trying with 158) the time spent is 17.01542377471924
Why does it take so long? Any possible solutions?
I’m new to Bokeh and I don’t know if this is the correct way to update plots.

@Marcos_Iturbe_Marenc you have not provided enough information to be able to speculate. In order to investigate we need a complete Minimal Reproducible Example that can actually be run. Failing that, all I can note is that the error message is due to trying to put columns with different lengths inside one ColumnDataSource. This is not allowed, a CDS is like a basic Pandas DataFrame, all columns must always have exactly the same length.

I will also note that varea_stack is not a basic single glyph. It is actually a convenience helper for coordinating multiple bar glyphs tied together with appropriate stack transforms. Depending on what you want to update, it may simply be much, much easier to just remove the old plot entirely, and replace it with a brand new plot, rather than trying to “update” the existing plot in place.

It doesn’t fail. The issue is that it takes 20 seconds to display.

I’m going to try this solution. Thank you so much.

1 Like

Sorry, this was a figure of speech. I did not mean the example was failing. I meant, “Unless you can provide an MRE, all I can note is …”

The issue is that it takes 20 seconds to display.

That’s very surprising but we would definitely need a complete code to run to reproduce in order to investigate.