Skip to content

Commit 69631b5

Browse files
committed
add zorder to multiple chart types
1 parent 2260b65 commit 69631b5

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

doc/python/graphing-multiple-chart-types.md

+38-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 design figures with multiple chart types in python.
2626
display_as: file_settings
@@ -208,5 +208,41 @@ fig.add_trace(
208208
fig.show()
209209
```
210210

211+
#### Trace Zorder
212+
213+
*New in 5.21*
214+
215+
You can move a trace in front of or behind another trace by setting its `zorder`. All traces have a default `zorder` of `0`. In the following example, we set `zorder` on the bar trace to `1` to move it in front of the scatter trace.
216+
217+
```python
218+
import plotly.graph_objects as go
219+
220+
x = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
221+
y_bar = [10, 15, 7, 10, 17, 15, 14, 20, 16, 19, 15, 17]
222+
y_area = [12, 13, 10, 14, 15, 13, 16, 18, 15, 17, 14, 16]
223+
224+
area_trace = go.Scatter(
225+
x=x,
226+
y=y_area,
227+
fill="tozeroy",
228+
mode="lines+markers",
229+
name="Area Trace with default `zorder` of 0",
230+
line=dict(color="lightsteelblue"),
231+
)
232+
233+
bar_trace = go.Bar(
234+
x=x,
235+
y=y_bar,
236+
name="Bar Trace with `zorder` of 1",
237+
zorder=1,
238+
marker=dict(color="lightslategray"),
239+
)
240+
241+
fig = go.Figure(data=[area_trace, bar_trace])
242+
243+
fig.show()
244+
245+
```
246+
211247
#### Reference
212248
See https://plotly.com/python/reference/ for more information and attribute options!

0 commit comments

Comments
 (0)