Altair zooming

I’m implementing altair in streamlit and I want to use zoom, pan function. When I looked at various posts, I found that some of the features are possible and others are not. Is this because of the version difference? Please tell me what to do if I want to zoom in or zoom out through the mouse.

Hi @eric_l

Can you share your code, please?

Thanks,
Charly

Hi @eric_l

Yes, Altair has documentations for both versions 5 (https://altair-viz.github.io/) and 4 (Vega-Altair: Declarative Visualization in Python — Altair 4.2.2 documentation) where there are differences in implementations of plots.

As for implementing the zoom/pan functionalities, you can append interactive() as a suffix to your plot.

Please see the following code snippet as an example:

import altair as alt
from vega_datasets import data

source = data.cars()

chart = alt.Chart(source).mark_circle().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
).interactive()

st.altair_chart(chart, theme=None, use_container_width=True)

The above code snippet was repurposed from this Docs: st.altair_chart - Streamlit Docs

Hope this helps!

1 Like

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