Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1092e8a

Browse files
committed
add example of updating nested object in restyle
1 parent 9ae4421 commit 1092e8a

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

plotly/widgets/graph_widget.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ def restyle(self, data, indices=None):
257257
258258
To update graph objects that are nested, like
259259
a marker's color, combine the keys with a period,
260-
e.g. `marker.color`
260+
e.g. `marker.color`. To replace an entire nested object,
261+
like `marker`, set the value to the object.
262+
See Example 2 below.
261263
262264
To update an attribute of multiple traces, set the
263265
value to an list of values. If the list is shorter
@@ -293,40 +295,46 @@ def restyle(self, data, indices=None):
293295
graph.restyle({'marker.color': 'red'})
294296
```
295297
296-
Example 2 - Set `marker.color` to red in the first trace of the graph
298+
Example 2 - Replace `marker` with {'color': 'red'}
299+
```
300+
graph.restyle({'marker': {'color': red'}})
301+
```
302+
303+
Example 3 - Set `marker.color` to red
304+
in the first trace of the graph
297305
```
298306
graph.restyle({'marker.color': 'red'}, indices=[0])
299307
```
300308
301-
Example 3 - Set `marker.color` of all of the traces to
309+
Example 4 - Set `marker.color` of all of the traces to
302310
alternating sequences of red and green
303311
```
304312
graph.restyle({'marker.color': ['red', 'green']})
305313
```
306314
307-
Example 4 - Set just `marker.color` of the first two traces
315+
Example 5 - Set just `marker.color` of the first two traces
308316
to red and green
309317
```
310318
graph.restyle({'marker.color': ['red', 'green']}, indices=[0, 1])
311319
```
312320
313-
Example 5 - Set multiple attributes of all of the traces
321+
Example 6 - Set multiple attributes of all of the traces
314322
```
315323
graph.restyle({
316324
'marker.color': 'red',
317325
'line.color': 'green'
318-
}, indices=[0, 1])
326+
})
319327
```
320328
321-
Example 6 - Update the data of the first trace
329+
Example 7 - Update the data of the first trace
322330
```
323331
graph.restyle({
324332
'x': [[1, 2, 3]],
325333
'y': [[10, 20, 30]],
326334
}, indices=[0])
327335
```
328336
329-
Example 7 - Update the data of the first two traces
337+
Example 8 - Update the data of the first two traces
330338
```
331339
graph.restyle({
332340
'x': [[1, 2, 3],

0 commit comments

Comments
 (0)