Plotly Express Line graph using fig.update_xaxes is blank

Hi. The goal is to create a chart with

  1. price values,
  2. a trend line (“ols”) overlay, and
  3. excluding weekend data.

However, after many tries using the code below, nothing works - it’s always blank or does not include one the chart goals listed above.

It has the following parameters:

  • X axis is date time
  • Y axis is float
  • dataframe is 7,500 rows

Platform:

  • Python language
  • MacBook Pro M1, running latest version of MacOS
  • I’ve tried using plotly.graph_objects too
  • Python is 3.9.13
  • Plotly Express is 5.8.2

Has anyone been able to create a graph like this on a Mac M1? If so can you post code snippets?

Thanks,

Dan.


Code:

   fig = px.scatter(df, x = "dateandtime"
                            , y = "Close"
                         # , color = "continent"
                         , log_x = False
                         , trendline = "ols"
                         # , trendline_options = dict(log_x = False)
                         , trendline_scope = "trace"
                         ,  title = "Test"
                         ,  height = 500
                         )

        # fig = px.scatter(df, x = df['dateandtime'], y = df['Close'])
        # fig = px.scatter(df, x = "dateandtime", y = "Close", trendline = "ols")
        # fig = px.scatter(df, x = "dateandtime", y = "Close")
        # fig = px.scatter(df, x = df['dateandtime'],y = df['Close'], trendline = "ols")
        # fig = go.Figure([go.Scatter(x = df['dateandtime'], y = df['Close'])], trendline = "ols")
        # fig = px.scatter(df, x = "total_bill", y = "tip", trendline = "ols")

        # fig = go.Figure([go.Scatter(x = df['dateandtime'], y = df['Close'])])
        # fig = px.line(x = df['dateandtime'], y = df['Close'])
        # fig = px.scatter(x = df['dateandtime'], y = df['Close'])
        # fig = px.scatter(df, x = 'dateandtime', y = 'Close')
        # fig = px.scatter(df, x = 'dateandtime', y = 'Close', )
        # fig = px.Figure([go.Scatter(x = df['dateandtime'], y = df['Close'])])

        fig.update_xaxes(rangeslider_visible = True,
            rangebreaks = [# NOTE: Below values are bound (not single values), ie. hide x to y
                dict(bounds=["sat", "mon"]),  # hide weekends, eg. hide sat to before mon
                dict(bounds=[13, 6.5], pattern="hour"),  # hide hours outside of 9.30am-4pm
                dict(values = ["2022-12-25", "2023-01-01"])  # hide holidays (Christmas and New Year's, etc)
            ]
        )

        fig.show()

Plotly does not create trend lines at all! After rebuilding my project on my WINDOWS workstation, the same error occurs!

Executing the code using either px or go, attempting a trend line ALWAYS fails and throws the error:

Bad property path:
trendline
^^^^^^^

There are a few thousand lines of code in the rest of my app. All work well. But Plotting has been a miserable experience.

At this point, I’ve lost complete faith in Plotly. I’ll need to try Matplotlib, seaborn, or one of the others.

Good bye,

Dan.