Skip to content

Commit 2ec424e

Browse files
non-business hour gaps
1 parent 6168134 commit 2ec424e

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

doc/python/time-series.md

+48-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.3.1
9+
jupytext_version: 1.4.2
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.8
23+
version: 3.7.7
2424
plotly:
2525
description: How to plot date and time in python.
2626
display_as: financial
@@ -207,7 +207,7 @@ import pandas as pd
207207
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
208208

209209
fig = px.scatter(df, x='Date', y='AAPL.High', range_x=['2015-12-01', '2016-01-15'],
210-
title="Hide Gaps with rangebreaks")
210+
title="Hide Weekend and Holiday Gaps with rangebreaks")
211211
fig.update_xaxes(
212212
rangebreaks=[
213213
dict(bounds=["sat", "mon"]), #hide weekends
@@ -216,3 +216,48 @@ fig.update_xaxes(
216216
)
217217
fig.show()
218218
```
219+
220+
### Hiding Non-Business Hours
221+
222+
The `rangebreaks` feature described above works for hiding hourly periods as well.
223+
224+
```python
225+
import plotly.express as px
226+
import pandas as pd
227+
import numpy as np
228+
np.random.seed(1)
229+
230+
work_week_40h = pd.date_range(start='2020-03-01', end='2020-03-07', freq="BH")
231+
232+
df = pd.DataFrame(dict(
233+
date = work_week_40h,
234+
value = np.cumsum(np.random.rand(40)-0.5)
235+
))
236+
237+
fig = px.scatter(df, x="date", y="value",
238+
title="Default Display with Gaps")
239+
fig.show()
240+
```
241+
242+
```python
243+
import plotly.express as px
244+
import pandas as pd
245+
import numpy as np
246+
np.random.seed(1)
247+
248+
work_week_40h = pd.date_range(start='2020-03-01', end='2020-03-07', freq="BH")
249+
250+
df = pd.DataFrame(dict(
251+
date = work_week_40h,
252+
value = np.cumsum(np.random.rand(40)-0.5)
253+
))
254+
255+
fig = px.scatter(df, x="date", y="value",
256+
title="Hide Non-Business Hour Gaps with rangebreaks")
257+
fig.update_xaxes(
258+
rangebreaks=[
259+
dict(bounds=[17, 9], pattern="hour"), #hide hours outside of 9am-5pm
260+
]
261+
)
262+
fig.show()
263+
```

0 commit comments

Comments
 (0)