Skip to content

Commit 2a25e1b

Browse files
committed
documented overwrite argument in update_*
1 parent 64e3bc0 commit 2a25e1b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

python/creating-and-updating-figures.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.1'
9-
jupytext_version: 1.1.6
9+
jupytext_version: 1.1.1
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -31,8 +31,8 @@ jupyter:
3131
page_type: example_index
3232
permalink: python/creating-and-updating-figures/
3333
redirect_from:
34-
- python/user-guide/
35-
- python/user-g/
34+
- python/user-guide/
35+
- python/user-g/
3636
thumbnail: thumbnail/creating-and-updating-figures.png
3737
v4upgrade: true
3838
---
@@ -438,6 +438,23 @@ fig.update_traces(
438438
fig.show()
439439
```
440440

441+
### Overwrite existing properties when using update methods
442+
443+
`update_layout` and `update_traces` have an `overwrite` keyword argument, defaulting to False, in which case updates are applied recursively to the *existing* nested property structure. When set to True, the prior value of existing properties is overwritten with the provided value.
444+
445+
In the example below, the red color of markers is overwritten when updating `marker` in `update_traces` with `overwrite=True`. Note that setting instead `marker_opacity` with the magic underscore would not overwrite `marker_color` because properties would be overwritten starting only at the level of `marker.opacity`.
446+
447+
```python
448+
import plotly.graph_objects as go
449+
fig = go.Figure(go.Bar(x=[1, 2, 3], y=[6, 4, 9],
450+
marker_color="red")) # will be overwritten below
451+
fig.update_traces(
452+
overwrite=True,
453+
marker={"opacity": 0.4}
454+
)
455+
fig.show()
456+
```
457+
441458
#### The for each trace method
442459
Suppose the updates that you want to make to a collection of traces depend on the current values of certain trace properties. The `update_traces` method cannot handle this situation, but the `for_each_trace` method can.
443460

0 commit comments

Comments
 (0)