Black Lives Matter. Please consider donating to Black Girls Code today.
https://www.blackgirlscode.com

One LOWESS Trend Per Scatter Plot with Colors

Is there a mechanisim to have a LOWESS trendline continuous in a scatter plot that has different coloring? See this example below.

That is created with the following.

    fig = px.scatter(
        df,
        x="TestTime",
        y="CorrectedLoad",
        color="SoftwareVersion",
        trendline="lowess",
        range_x=[start_date, end_date],
        title=f"{DUTModel} | Acceptable Frame Loss 0.5% | 1000 Flows BiDi",
        template="ggplot2",
        labels={
            "CorrectedLoad": "Throughput (Mbps)",
            "TestTime": "Test Timestamp",
            "SoftwareVersion": "Software Version",
        },
    )

plotly-express==0.4.1
plotly==4.8.2

Hi @MrPaul, this is not possible in a single plotly.express call since px computes a trendline for each trace, and a different trace is created for each categorical value of the color argument. However, you can compute the trendline for the whole dataset without separating the data into several traces, and then add this trendline to the px figure created with a color argument. For example

import plotly.express as px
df = px.data.tips()
fig = px.scatter(df, x='total_bill', y='tip', trendline='lowess')
fig.update_traces(line_color='black')
fig_color = px.scatter(df, x='total_bill', y='tip', color='smoker')
fig_color.add_trace(fig.data[1])
fig_color.show()

PS: you should uninstall plotly-express it’s now part of the main plotly package.