altair icon indicating copy to clipboard operation
altair copied to clipboard

Interactive sliders for transforms like LOESS

Open ProfEiz opened this issue 1 year ago • 1 comments

It seems that it is not possible to create a slider bar / interactive parameter for a transform, like LOESS.

`loess_slider = alt.binding_range(min=0, max=1, step= .02, name='bandwidth')
loess_var = alt.param(bind=loess_slider, value=.3)

chart = alt.Chart(df).mark_point().encode(
    x='horsepower',
    y='mpg',
    color = 'origin', 
).interactive(). add_params(
    loess_var
)

chart + chart.transform_loess('horsepower','mpg', bandwidth= loess_var).mark_line()`

Code above will not accept the bandwidth = slider-value parameter, though if I simply set the loess variable equal to a valid number, it works fine.

Separately, scipy.interpolation has a really nice cubic spline that is likely a better local smoother. But I assume that same problem will apply.

Expected use behavior would be to allow users to "tune" the LOESS interactively.

ProfEiz avatar Jan 02 '24 17:01 ProfEiz

I don't think transforms accepts parameters yet. The docs mention that you can only use a number https://altair-viz.github.io/user_guide/transform/loess.html. This would need to be implemented in Vega-Lite before it becomes available in altair..

joelostblom avatar Jan 02 '24 18:01 joelostblom