Skip to content

Commit 131fe09

Browse files
committed
add legend indentation example
1 parent e336af4 commit 131fe09

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

Diff for: doc/python/legend.md

+41-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.7
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.10.4
23+
version: 3.10.11
2424
plotly:
2525
description: How to configure and style the legend in Plotly with Python.
2626
display_as: file_settings
@@ -546,6 +546,45 @@ fig.update_layout(title="Try Clicking on the Legend Items!")
546546
fig.show()
547547
```
548548

549+
```python
550+
df = data.iris()
551+
df
552+
```
553+
554+
#### Indent Legend Entries
555+
556+
*New in 5.20*
557+
558+
To indent legend entries, set `indenation` on `layout.legend` to a number of pixels. In the following example, we indent legend entries by 10 pixels.
559+
560+
```python
561+
import plotly.graph_objects as go
562+
from plotly import data
563+
564+
df = data.iris()
565+
566+
fig = go.Figure(
567+
[
568+
go.Scatter(
569+
x=df[df["species"] == species]["sepal_width"],
570+
y=df[df["species"] == species]["sepal_length"],
571+
mode="markers",
572+
name=species,
573+
)
574+
for species in df["species"].unique()
575+
],
576+
layout=dict(
577+
legend=dict(
578+
title="Species",
579+
indentation=10
580+
)
581+
),
582+
)
583+
584+
585+
fig.show()
586+
```
587+
549588
#### Group click toggle behavior
550589

551590
*New in v5.3*

0 commit comments

Comments
 (0)