St.pyplot() matplotlib figure with navigation toolbar?

When using matplotlib.pyplot outside of Streamlit, the figure comes up and allows user interaction with a very nice navigation toolbar with zoom, pan, etc…is there a way to get this while working inside Streamlit, with st.pyplot() ?

Not right out the box with st.pyplot() because it just export the figure as a static image. You can try mpld3 ( to export a matplotlib figure to an interactive js-html and embed that in an iframe (Components API - Streamlit Docs).


import streamlit as st
import matplotlib.pyplot as plt, mpld3

fig, ax = plt.subplots()
ax.plot([3,1,4,1,5], 'rs-', label='My line')
ax.set(xlabel="X axis", ylabel="Y axis")

htmlfig = mpld3.fig_to_html(fig)

"# 📊 Matplotlib, `mpld3` & streamlit"
st.components.v1.html(htmlfig, height=500)

Of course, you can try other plotting libraries that are focused on web interactivity like plotly or altair.

Ah, ok.
I did not know about mpld3, altair; I had heard of plotly and bokeh.
Will look into these web-oriented libraries.