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 (http://mpld3.github.io/) to export a matplotlib figure to an interactive js-html and embed that in an iframe (Components API - Streamlit Docs).

mpld3Example

Code:
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")
ax.legend(title="Legend")

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.
Thanks.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.