vega / altair

Declarative statistical visualization library for Python
https://altair-viz.github.io/
BSD 3-Clause "New" or "Revised" License
9.24k stars 787 forks source link

Interactive sliders for transforms like LOESS #3306

Open ProfEiz opened 8 months ago

ProfEiz commented 8 months ago

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.

joelostblom commented 8 months ago

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