Skip to content

Pluggable trendlines #2418

@nicolaskruchten

Description

@nicolaskruchten

To address issues like #1763 and plotly/plotly_express#31 I think we should generalize the PX trendline kwarg to:

  1. Look strings up in a registry of known trendline functions, like renderers and templates do, so that we can keep "ols" and "trendline" but also allow people to add their own.
  2. Also accept functions if people don't want to have to register them to use them.
  3. Probably add trendline_args as a set of arguments people can pass to parameterize their trendlines.

If we stick with allowing this mostly on scatter plots and returning new scatter traces then this is pretty easy... we might want to allow this on bar charts (sometimes people ask) or maybe go big and allow it for all charts, in which case "trendline" is the wrong name. I'm thinking here of allowing, say, KDE on histograms, or moving averages on bars.

Either way, the basic idea is that for each trace we normally add in the figure, we add another one by calling this trendline function, so people could do stuff like confidence intervals, error bands, different kinds of regressions, non-linear fits, parameterized LOWESS etc etc.

One additional thing to think about is how this relates to the idea of generating a trendline for the whole dataset or per facet instead of per trace: sometimes people want to do basically one trendline for the whole dataset, but then break it out by color. This would mean we would need to do some extra grouping. Something similar comes up when we think about doing marginal plots when using facet_row and facet_col: we would need to reaggregate differently there too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions