Skip to content

Commit cb07e20

Browse files
committed
Update selections.md
1 parent e2eb238 commit cb07e20

File tree

1 file changed

+110
-2
lines changed

1 file changed

+110
-2
lines changed

doc/python/selections.md

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,123 @@ fig.show()
138138

139139
## Selections with Time Series
140140

141-
Selections are also supported on time series figures. Here, we add a rectangular selection with a region between the dates `2019-01-01"` and `"2019-10-01"` on the x axis and between `1` and `1.15` on the y axis.
141+
Selections are also supported on time series figures. Here, we add a rectangular selection with a region between the dates `2019-01-01"` and `"2019-10-01"` on the x axis and between `0.95` and `1.17` on the y axis.
142142

143143

144144
```python
145145
import plotly.express as px
146146

147147
df = px.data.stocks()
148148
fig = px.line(df, x='date', y="GOOG")
149-
fig.add_selection(x0="2019-01-01", y0=1, x1="2019-10-01", y1=1.17)
149+
fig.add_selection(x0="2019-01-01", y0=0.95, x1="2019-10-01", y1=1.17)
150+
fig.show()
151+
```
152+
153+
## Selections on Subplots
154+
155+
156+
You can add selections to subplots by specifying axis ids using `xaxis` and `yaxis`. Here, we add one selection on the plot with axis ids `x` and `y2` and two selections to the the plot with axis ids `x` and `y`.
157+
158+
```python
159+
import plotly.graph_objects as go
160+
161+
import numpy as np
162+
163+
t = np.linspace(-1, 1.2, 2000)
164+
x = (t**3) + (0.3 * np.random.randn(2000))
165+
y = (t**6) + (0.3 * np.random.randn(2000))
166+
167+
fig = go.Figure()
168+
fig.add_trace(go.Histogram2dContour(
169+
x = x,
170+
y = y,
171+
colorscale = 'Blues',
172+
reversescale = True,
173+
xaxis = 'x',
174+
yaxis = 'y'
175+
))
176+
fig.add_trace(go.Scatter(
177+
x = x,
178+
y = y,
179+
xaxis = 'x',
180+
yaxis = 'y',
181+
mode = 'markers',
182+
marker = dict(
183+
color = 'rgba(0,0,0,0.3)',
184+
size = 3
185+
)
186+
))
187+
fig.add_trace(go.Histogram(
188+
y = y,
189+
xaxis = 'x2',
190+
marker = dict(
191+
color = 'rgba(0,0,0,1)'
192+
)
193+
))
194+
fig.add_trace(go.Histogram(
195+
x = x,
196+
yaxis = 'y2',
197+
marker = dict(
198+
color = 'rgba(0,0,0,1)'
199+
)
200+
))
201+
202+
fig.update_layout(
203+
autosize = False,
204+
xaxis = dict(
205+
zeroline = False,
206+
___domain = [0,0.85],
207+
showgrid = False
208+
),
209+
yaxis = dict(
210+
zeroline = False,
211+
___domain = [0,0.85],
212+
showgrid = False
213+
),
214+
xaxis2 = dict(
215+
zeroline = False,
216+
___domain = [0.85,1],
217+
showgrid = False
218+
),
219+
yaxis2 = dict(
220+
zeroline = False,
221+
___domain = [0.85,1],
222+
showgrid = False
223+
),
224+
height = 600,
225+
width = 600,
226+
bargap = 0,
227+
hovermode = 'closest',
228+
showlegend = False,
229+
selections = [{
230+
"x0": 0.5,
231+
"x1": -0.5,
232+
"xref": "x",
233+
"y0": 190,
234+
"y1": 0,
235+
"yref": "y2",
236+
"line":dict(color="yellow")
237+
}, {
238+
"x0": -0.2,
239+
"x1": -1.5,
240+
"xref": "x",
241+
"y0": 2,
242+
"y1": -1,
243+
"yref": "y",
244+
"line":dict(
245+
color="yellow"
246+
)
247+
}, {
248+
"path": "M0.75,2.39L0.98,3.38L1.46,3.68L1.80,3.35L2.01,2.51L1.67,1.15L1.18,0.50L0.65,0.66L0.54,0.83L0.49,1.56Z",
249+
"xref": "x",
250+
"yref": "y",
251+
"line":dict(
252+
color="yellow"
253+
)
254+
}]
255+
)
256+
257+
150258
fig.show()
151259
```
152260

0 commit comments

Comments
 (0)