Saving altair charts with active theme

Is there a way to programatically save an Altair chart so that it looks the same as displayed by Streamlit?

As it is now, doing

chart = alt.Chart(df).encode(...)
st.altair_chart(chart)
chart.save('figure.pdf')

shows the chart using the Streamlit theme, but the saved chart uses the default Altair theme…

Edit/update: I found that I can get a consistent result using one of the registered Vega themes (run alt.vegalite.themes for a list) and disabling the ‘streamlit’ theme in st.altair_chart:

alt.themes.enable('powerbi')
st.altair_chart(chart, theme=None)
chart.save('figure.pdf')

This works for most themes, but ‘urbaninstitute’ fails due to missing font (‘Lato’) and the ‘dark’ theme is somehow negated by streamlit, so it shows with white background, while the saved pdf has black.

So, I believe that if I could register/activate the ‘streamlit’ theme with altair/vega, it would work as well - some ideas?

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