streamlit / streamlit

Streamlit — A faster way to build and share data apps.
https://streamlit.io
Apache License 2.0
34.55k stars 3k forks source link

Add support for `trendline` argument in `st.scatter_chart` #9353

Open EwoutH opened 2 weeks ago

EwoutH commented 2 weeks ago

Checklist

Summary

Add support for trendlines in Streamlit's scatter_chart, similar to Plotly's trendline functionality. This feature would allow users to easily add linear or non-linear trendlines to their scatter charts.

Why?

Currently, Streamlit's scatter_chart does not support the addition of trendlines, which limits its functionality for users who need to analyze data trends. Trendlines are essential for visualizing relationships between variables, identifying patterns, and making predictions. Adding this feature would bring Streamlit's visualization capabilities closer to those of Plotly Express, making it more powerful and versatile for data analysis.

How?

The solution would involve modifying the scatter_chart function in Streamlit to accept a trendline argument, similar to how Plotly Express handles it. This argument could accept values like "ols" for Ordinary Least Squares regression, "lowess" for Locally Weighted Scatterplot Smoothing, and possibly other options for moving averages or exponential smoothing.

Additional Context

See the Plotly docs:

github-actions[bot] commented 2 weeks ago

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Visits

EwoutH commented 2 weeks ago

I now see Vega-Lite is used under the hood, not Plotly. With Vega-Lite it might be a bit more complex.

But it would still be useful.

jrieke commented 2 weeks ago

Thanks for the feature request! Just for context, we're trying to keep st.scatter_chart and all other built-in charting commands relatively minimal, since we don't want to invent yet another plotting framework. For more complex charts, it's recommended to use Altair or Plotly itself with st.altair_chart or st.plotly_chart. But will keep this open, and if lots of people want it, we might consider it!