Fastest plotting library?

I would like to display a plot that updates over real time based on predictions, similar to the Plotting Demo in the hello example. However, st.chart() is fast, but has too limited customization. Currently I am trying matplotlib, but the results are being displayed too slow.

How do the other available plotting libraries that work with streamlit (bokeh, plotly, Vega Lite etc.) compare with matplotlib based on customization and especially speed?

1 Like

Hey @kcambrek, welcome to Streamlit!

Under the hood, st.chart() uses Altair, which is a library for declaratively building interactive charts that are then displayed in the browser with Vega-Lite.

(Matplotlib, in contrast, is not a browser-aware library; instead, it creates non-interactive charts that Streamlit displays as static images. Any time you make a change to a Matplotlib chart, Streamlit has to re-render the entire thing to an image, and then send that image to the browser, which is much slower.)

Streamlit can handle arbitrary Altair charts via the st.altair_chart() function. The Altair docs have a ton of great examples you can use to get started on more sophisticated charts!

Streamlit also has support for deck.gl which can be used to create really stunning charts. But you don’t get the benefit of using Python syntax to declare your chart, like you do with Altair; instead, you’ll need to describe your chart in deck.gl’s json syntax. (The deck.gl playground can help you with this.)

My personal preference is Altair, because it’s Python and therefore comfortable to work in from a Streamlit script - unless I’m trying to get the most beautiful visuals possible, in which case I’d reach for deck.gl.

3 Likes

I agree with @tim. I’d use Altair plus Streamlit’s add_rows for this! :chart_with_upwards_trend:

2 Likes