Hi. The goal is to create a chart with
- price values,
- a trend line (“ols”) overlay, and
- 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()