Skip to content

Commit d7d6a51

Browse files
committed
add trace to magic underscore example
1 parent cacbc37 commit d7d6a51

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

notebooks/creating-updating-figures.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,27 @@ fig.show()
216216
```
217217

218218
### Magic underscore notation
219-
To make it easier to work with nested properties graph object constructors, and many graph object methods, support magic underscore notation. This allows you to reference nested properties by joining together multiple nested property names with underscores. For example, specifying the figure title in the figure constructor *without* magic underscore notation requires setting the `layout` argument to `dict(title=dict(text="A Chart"))`.
219+
To make it easier to work with nested properties graph object constructors, and many graph object methods, support magic underscore notation. This allows you to reference nested properties by joining together multiple nested property names with underscores.
220+
221+
For example, specifying the figure title in the figure constructor *without* magic underscore notation requires setting the `layout` argument to `dict(title=dict(text="A Chart"))`. Similarly, setting the line color of a scatter trace requires setting the `marker` property to `dict(color="crimson")`.
220222

221223
```python
222224
import plotly.graph_objects as go
223-
fig = go.Figure(layout=dict(title=dict(text="A Chart")))
225+
fig = go.Figure(
226+
data=[go.Scatter(y=[1, 3, 2], line=dict(color="crimson"))],
227+
layout=dict(title=dict(text="A Chart"))
228+
)
224229
fig.show()
225230
```
226231

227-
With magic underscore notation, you can accomplish the same thing by passing the figure constructor a keyword argument named `layout_title_text` with the value `"A Chart"`.
232+
With magic underscore notation, you can accomplish the same thing by passing the figure constructor a keyword argument named `layout_title_text`, and by passing the `go.Scatter` constructor a keyword argument named `line_color`.
228233

229234
```python
230235
import plotly.graph_objects as go
231-
fig = go.Figure(layout_title_text="A Chart")
236+
fig = go.Figure(
237+
data=[go.Scatter(y=[1, 3, 2], line_color="crimson")],
238+
layout_title_text="A Chart"
239+
)
232240
fig.show()
233241
```
234242

0 commit comments

Comments
 (0)