I'd like to be able to zoom into my time series in altair. I understand that this is currently still work in progress, but I hoped to be able to circumvent this restriction by the following idea
import numpy as np
import altair as alt
import polars as pl
n = 1000
x = np.linspace(0, 10, 1000)
y = np.sin(x) + np.sin(10 * x) * 0.2
df = pl.DataFrame({"x": x, "y": y})
brush = alt.selection_interval(encodings=["x"])
(
alt.Chart(df) # type: ignore
.mark_point()
.encode(
x=alt.X("x:Q").scale(domain=brush.ref()),
y="y:Q",
color=alt.condition(brush, alt.value("red"), alt.value("lightgray")), # type: ignore
)
.add_params(brush)
.properties(width=1200, height=600)
)
The idea was to apply the brush's ref as the x-domain. However, the update of the x-axis triggers immediately upon open up the selection. It would need to only trigger upon the subsequent release of the mouse. I know that there's an on field for the selection_interval, but I am unable to get this working.
Is there a away to apply the update for the x-domain only after releasing the selection?





Does it need to be in Altair? There are other python libraries which are more optimized for zooming in on timeseries data. For example Plotly + Plotly Resampler.