Skip to content

Commit 5a779bc

Browse files
committed
add zorder line example
1 parent b2721ed commit 5a779bc

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

doc/python/line-and-scatter.md

+44-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.16.1
1010
kernelspec:
1111
display_name: Python 3 (ipykernel)
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.8.0
23+
version: 3.10.11
2424
plotly:
2525
description: How to make scatter plots in Python with Plotly.
2626
display_as: basic
@@ -426,6 +426,48 @@ fig = go.Figure(data=go.Scatter(
426426
fig.show()
427427
```
428428

429+
#### Trace Zorder
430+
431+
*New in 5.21*
432+
433+
For many trace types, including `go.Scatter`, you can define the order traces are drawn in by setting a `zorder`. Traces with a higher `zorder` appear at the front, with traces with a lower `zorder` at the back. In this example, we give our trace for 'France' the highest `zorder`, meaning it is drawn in front of the other two traces:
434+
435+
```python
436+
import plotly.graph_objects as go
437+
import plotly.data as data
438+
439+
df = data.gapminder()
440+
441+
df_europe = df[df['continent'] == 'Europe']
442+
443+
trace1 = go.Scatter(x=df_europe[df_europe['country'] == 'France']['year'],
444+
y=df_europe[df_europe['country'] == 'France']['lifeExp'],
445+
mode='lines+markers',
446+
zorder=3,
447+
name='France',
448+
marker=dict(size=15))
449+
450+
trace2 = go.Scatter(x=df_europe[df_europe['country'] == 'Germany']['year'],
451+
y=df_europe[df_europe['country'] == 'Germany']['lifeExp'],
452+
mode='lines+markers',
453+
zorder=1,
454+
name='Germany',
455+
marker=dict(size=15))
456+
457+
trace3 = go.Scatter(x=df_europe[df_europe['country'] == 'Spain']['year'],
458+
y=df_europe[df_europe['country'] == 'Spain']['lifeExp'],
459+
mode='lines+markers',
460+
zorder=2,
461+
name='Spain',
462+
marker=dict(size=15))
463+
464+
layout = go.Layout(title='Life Expectancy in Europe Over Time')
465+
466+
fig = go.Figure(data=[trace1, trace2, trace3], layout=layout)
467+
468+
fig.show()
469+
```
470+
429471
#### Large Data Sets
430472

431473
Now in Plotly you can implement WebGL with `Scattergl()` in place of `Scatter()` <br>

0 commit comments

Comments
 (0)