This is the graph with this code
fig.update_yaxes(gridcolor=‘lightgrey’, gridwidth=0.5)
fig.update_xaxes(
rangeslider_visible=False,
rangebreaks=[
dict(bounds=[“sat”, “mon”]),
#hide weekends
dict(values=[“2023-12-25”, “2023-01-01”]), # hide Christmas and New Year’s
dict(bounds=[20, 4], pattern=“hour”)
]
)
You see there is a line it is between 13 January to 17 January because of the MLK Jr. day I think to fix that I add this
fig.update_yaxes(gridcolor=‘lightgrey’, gridwidth=0.5)
fig.update_xaxes(
rangeslider_visible=False,
rangebreaks=[
dict(bounds=[“sat”, “mon”]), #hide weekends
dict(values=[“2023-12-25”, “2023-01-01”]), # hide Christmas and New Year’s
dict(values=[“2023-01-16”]), # hide MLK Jr. Day
dict(bounds=[20, 4], pattern=“hour”)
]
)
but my graph turned to this
It’s like tangled I don’t know why ?
Support for discontinuous time series data allows you to exclude market holidays and national holidays by specifying dates that are not included in the original data, without specifying the day of the week. I created a graph based on the example in the reference with a list of excluded dates.
import plotly.express as px
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
# Extract dates that are not in the data frame dates
all_days = [x.strftime('%Y-%m-%d') for x in pd.date_range(df.Date.min(), df.Date.max(), freq='1d').date.tolist()]
break_days = df.Date.tolist()
new_break_days = set(all_days) - set(break_days)
fig = px.line(df,
x='Date',
y='AAPL.High',
range_x=['2015-12-01', '2016-01-30'],
title="Hide Weekend and Holiday Gaps with rangebreaks")
fig.update_xaxes(
rangebreaks=[
#dict(bounds=["sat", "mon"]), #hide weekends
dict(values=sorted(list(new_break_days)))
]
)
fig.show()
1 Like