Skip to content

Commit 85e24bc

Browse files
committed
No chaining
1 parent 46f0d51 commit 85e24bc

File tree

1 file changed

+58
-58
lines changed

1 file changed

+58
-58
lines changed

notebooks/templates.md

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ gapminder = px.data.gapminder()
5151
gapminder_2007 = gapminder.query("year==2007")
5252

5353
for template in ["plotly", "plotly_white", "plotly_dark", "ggplot2", "seaborn", "none"]:
54-
px.scatter(gapminder_2007,
55-
x="gdpPercap", y="lifeExp", size="pop", color="continent",
56-
log_x=True, size_max=60,
57-
template=template, title="Gapminder 2007: '%s' theme" % template
58-
).show()
54+
fig = px.scatter(gapminder_2007,
55+
x="gdpPercap", y="lifeExp", size="pop", color="continent",
56+
log_x=True, size_max=60,
57+
template=template, title="Gapminder 2007: '%s' theme" % template)
58+
fig.show()
5959
```
6060

6161
### Specifying themes to graph object figures
@@ -71,12 +71,13 @@ fig = go.Figure(
7171
data=go.Surface(z=z_data.values),
7272
layout=go.Layout(
7373
title="Mt Bruno Elevation",
74-
width=500,
74+
width=500,
7575
height=500,
76-
))
76+
))
7777

7878
for template in ["plotly", "plotly_white", "plotly_dark", "ggplot2", "seaborn", "none"]:
79-
fig.update_layout(template=template, title="Mt Bruno Elevation: '%s' theme" % template).show()
79+
fig.update_layout(template=template, title="Mt Bruno Elevation: '%s' theme" % template)
80+
fig.show()
8081
```
8182

8283
### Specifying a default themes
@@ -93,11 +94,11 @@ pio.templates.default = "plotly_white"
9394
gapminder = px.data.gapminder()
9495
gapminder_2007 = gapminder.query("year==2007")
9596

96-
px.scatter(gapminder_2007,
97-
x="gdpPercap", y="lifeExp", size="pop", color="continent",
98-
log_x=True, size_max=60,
99-
title="Gapminder 2007: current default theme"
100-
).show()
97+
fig = px.scatter(gapminder_2007,
98+
x="gdpPercap", y="lifeExp", size="pop", color="continent",
99+
log_x=True, size_max=60,
100+
title="Gapminder 2007: current default theme")
101+
fig.show()
101102
```
102103

103104
### Disable default theming
@@ -125,10 +126,10 @@ large_rockwell_template = go.layout.Template(
125126
layout=go.Layout(dict(title=dict(font=dict(family="Rockwell", size=24))))
126127
)
127128

128-
(go.Figure()
129-
.update_layout(title="Figure Title",
130-
template=large_rockwell_template)
131-
).show()
129+
fig = go.Figure()
130+
fig.update_layout(title="Figure Title",
131+
template=large_rockwell_template)
132+
fig.show()
132133
```
133134

134135
### The template data property
@@ -142,10 +143,10 @@ import plotly.graph_objects as go
142143
diamond_template = go.layout.Template()
143144
diamond_template.data.scatter = [go.Scatter(marker=dict(symbol="diamond", size=20))]
144145

145-
(go.Figure()
146-
.update_layout(template=diamond_template)
147-
.add_scatter(y=[2, 1, 3], mode="markers")
148-
).show()
146+
fig = go.Figure()
147+
fig.update_layout(template=diamond_template)
148+
fig.add_scatter(y=[2, 1, 3], mode="markers")
149+
fig.show()
149150
```
150151

151152
If a trace type property is set to a list of more than one trace, then the default properties are cycled as more traces are added to the figure. Here is an example that creates a template that cycles the default marker symbol for scatter traces, and then constructs a figure that uses this template.
@@ -159,14 +160,13 @@ symbol_template.data.scatter = [
159160
go.Scatter(marker=dict(symbol="square", size=10)),
160161
go.Scatter(marker=dict(symbol="circle", size=10)),
161162
]
162-
163-
(go.Figure()
164-
.update_layout(template=symbol_template)
165-
.add_scatter(y=[1, 2, 3], mode="markers", name="first")
166-
.add_scatter(y=[2, 3, 4], mode="markers", name="second")
167-
.add_scatter(y=[3, 4, 5], mode="markers", name="third")
168-
.add_scatter(y=[4, 5, 6], mode="markers", name="forth")
169-
).show()
163+
fig = go.Figure()
164+
fig.update_layout(template=symbol_template)
165+
fig.add_scatter(y=[1, 2, 3], mode="markers", name="first")
166+
fig.add_scatter(y=[2, 3, 4], mode="markers", name="second")
167+
fig.add_scatter(y=[3, 4, 5], mode="markers", name="third")
168+
fig.add_scatter(y=[4, 5, 6], mode="markers", name="forth")
169+
fig.show()
170170
```
171171

172172
Note that because we built the template with a list of 3 scatter trace graph objects (one each for the diamond, square, and circle symbols), the forth scatter trace in the figure cycles around and takes on the defaults specified in the first template trace (The diamond symbol).
@@ -184,16 +184,15 @@ import plotly.graph_objects as go
184184

185185
annotation_template = go.layout.Template()
186186
annotation_template.layout.annotationdefaults = go.layout.Annotation(font=dict(color="crimson"))
187-
188-
(go.Figure()
189-
.update_layout(
187+
fig = go.Figure()
188+
fig.update_layout(
190189
template=annotation_template,
191190
annotations=[
192191
go.layout.Annotation(text="Look Here", x=1, y=1),
193192
go.layout.Annotation(text="Look There", x=2, y=2)
194193
]
195194
)
196-
).show()
195+
fig.show()
197196
```
198197

199198
### Including array elements in a theme
@@ -223,9 +222,9 @@ draft_template.layout.annotations = [
223222
)
224223
]
225224

226-
(go.Figure()
227-
.update_layout(template=draft_template)
228-
).show()
225+
fig=go.Figure()
226+
fig.update_layout(template=draft_template)
227+
fig.show()
229228
```
230229

231230
### Customizing theme array elements in a figure
@@ -252,17 +251,17 @@ draft_template.layout.annotations = [
252251
)
253252
]
254253

255-
(go.Figure()
256-
.update_layout(
257-
template=draft_template,
258-
annotations=[
259-
go.layout.Annotation(
260-
templateitemname="draft watermark",
261-
text="CONFIDENTIAL",
262-
)
263-
]
264-
)
265-
).show()
254+
fig = go.Figure()
255+
fig.update_layout(
256+
template=draft_template,
257+
annotations=[
258+
go.layout.Annotation(
259+
templateitemname="draft watermark",
260+
text="CONFIDENTIAL",
261+
)
262+
]
263+
)
264+
fig.show()
266265
```
267266

268267
### Registering themes as named templates
@@ -291,9 +290,9 @@ pio.templates["draft"] = go.layout.Template(
291290
]
292291
)
293292

294-
(go.Figure()
295-
.update_layout(template="draft")
296-
).show()
293+
fig = go.Figure()
294+
fig.update_layout(template="draft")
295+
fig.show()
297296
```
298297

299298
It is also possible to set your own custom template as the default so that you do not need to pass it by name when constructing graph object figures or calling plotly express functions.
@@ -320,7 +319,8 @@ pio.templates["draft"] = go.layout.Template(
320319
)
321320
pio.templates.default = "draft"
322321

323-
go.Figure().show()
322+
fig = go.Figure()
323+
fig.show()
324324
```
325325

326326
### Combining themes
@@ -352,7 +352,8 @@ pio.templates["draft"] = go.layout.Template(
352352
)
353353
pio.templates.default = "plotly+draft"
354354

355-
go.Figure().show()
355+
fig = go.Figure()
356+
fig.show()
356357
```
357358

358359
Combining themes is also supported by plotly express
@@ -381,12 +382,11 @@ pio.templates.default = "plotly+draft"
381382

382383
gapminder = px.data.gapminder()
383384
gapminder_2007 = gapminder.query("year==2007")
384-
385-
px.scatter(gapminder_2007,
386-
x="gdpPercap", y="lifeExp", size="pop", color="continent",
387-
log_x=True, size_max=60,
388-
title="Gapminder 2007: current default theme"
389-
).show()
385+
fig = px.scatter(gapminder_2007,
386+
x="gdpPercap", y="lifeExp", size="pop", color="continent",
387+
log_x=True, size_max=60,
388+
title="Gapminder 2007: current default theme")
389+
fig.show()
390390
```
391391

392392
<!-- #region -->

0 commit comments

Comments
 (0)