Skip to content

Commit 36c559b

Browse files
legendrank docs
1 parent b9eee35 commit 36c559b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

doc/python/legend.md

+17-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.2'
9-
jupytext_version: 1.6.0
9+
jupytext_version: 1.4.2
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.6
23+
version: 3.7.7
2424
plotly:
2525
description: How to configure and style the legend in Plotly with Python.
2626
display_as: file_settings
@@ -97,6 +97,21 @@ fig.add_trace(go.Bar(name="fourth", x=["a", "b"], y=[2,1]))
9797
fig.show()
9898
```
9999

100+
*New in v5.0*
101+
102+
The `legendrank` attribute of a trace can be used to control its placement within the legend, without regard for its placement in the `data` list. The default `legendrank` for traces is 1000 and ties are broken as described above, meaning that any trace can be pulled up to the top if it is the only one with a legend rank less than 1000 and pushed to the bottom if it is the only one with a rank greater than 1000.
103+
104+
```python
105+
import plotly.graph_objects as go
106+
107+
fig = go.Figure()
108+
fig.add_trace(go.Bar(name="fourth", x=["a", "b"], y=[2,1], legendrank=4))
109+
fig.add_trace(go.Bar(name="second", x=["a", "b"], y=[2,1], legendrank=2))
110+
fig.add_trace(go.Bar(name="first", x=["a", "b"], y=[1,2], legendrank=1))
111+
fig.add_trace(go.Bar(name="third", x=["a", "b"], y=[1,2], legendrank=3))
112+
fig.show()
113+
```
114+
100115
#### Showing and Hiding the Legend
101116

102117
By default the legend is displayed on Plotly charts with multiple traces, and this can be explicitly set with the `layout.showlegend` attribute:

0 commit comments

Comments
 (0)