Speeding up Matplotlib With Changing the Data

Hey everyone,
I have multiple engineering calculation pages with Streamlit and all depends on Matplotlib. For some calculations, it may take some time, so I am searching for methods to speed up the Matplotlib without switching to “browser-aware” plotters.
There is a method to change the data of the plot instead of creating new ones. However, I am not sure if I can do this in Streamlit.
if I say something like:
if plot exists, change the value to this
if plot does not exist, create the plot
For streamlit, it always creates the plot from all over again when data is changed and script is re-runed… Is there any way to keep the figure from previous phase so that I can change the data? Note that plot is created in outside functions in almost all cases and returned to main Streamlit file.

If this is a constraint, then you’re pretty much out of luck. matplotlib is a slower library within Streamlit compared to plotly, altair and so on. The advanced differencing that you are talking about isn’t part of matplotlib, which re-draws the entire scene each time.

Best,
Randy