Skip to content

[BUG] px.scatter "ols" not producing linear trend line #3683

Closed
@jconoranderson

Description

@jconoranderson

Describe your context
Please provide us your environment, so we can easily reproduce the issue.

  • replace the result of pip list | grep dash below
dash                               2.3.1
dash-auth                          1.4.1
dash-bootstrap-components          1.0.2
dash-core-components               2.0.0
dash-html-components               2.0.0
dash-table                         5.0.0
  • if frontend related, tell us your Browser, Version and OS

    • OS: macOS Version 12.2.1 (21D62)
    • Browser: Chrome
    • Version: 100.0.4896.88 (Official Build) (x86_64)

Describe the bug

"ols" (original least squares) function to add a linear trend line is not producing a regression line. It is instead something closer to polynomial.

The code I'm using to create the graph is as follows:

 elif beh_gph == 'ols':
            dfg[date_frmt] = pd.to_datetime(dfg[date_frmt])
            print(dfg)
            fig = px.scatter(dfg, x=date_frmt, y="Episode_Count", color="Target",
                             labels={"Episode_Count": tally + " per Shift",
                                     "Target": "Target",
                                     "Yr_Mnth": "Date"},
                             trendline="ols", title="Aggregate Behavior Data: " + patient + " - " + today)
            fig.update_xaxes(tickangle=45,)
            fig.update_layout(template='plotly_white', hovermode="x unified")

Instead of a logistic regression line per the example here - https://plotly.com/python/linear-fits/

I'm getting this:

enter image description here

The x and y values are just floating point numbers and date values respectively.

The Plotly version is 5.7.0

Expected behavior

Linear regression line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions