6
6
extension : .md
7
7
format_name : markdown
8
8
format_version : ' 1.2'
9
- jupytext_version : 1.3.1
9
+ jupytext_version : 1.4.2
10
10
kernelspec :
11
11
display_name : Python 3
12
12
language : python
@@ -20,7 +20,7 @@ jupyter:
20
20
name : python
21
21
nbconvert_exporter : python
22
22
pygments_lexer : ipython3
23
- version : 3.6.8
23
+ version : 3.7.7
24
24
plotly :
25
25
description : How to plot date and time in python.
26
26
display_as : financial
@@ -207,7 +207,7 @@ import pandas as pd
207
207
df = pd.read_csv(' https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv' )
208
208
209
209
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" )
211
211
fig.update_xaxes(
212
212
rangebreaks = [
213
213
dict (bounds = [" sat" , " mon" ]), # hide weekends
@@ -216,3 +216,48 @@ fig.update_xaxes(
216
216
)
217
217
fig.show()
218
218
```
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