You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/python/figure-labels.md
+64-7
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,8 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.1'
9
-
jupytext_version: 1.2.1
8
+
format_version: '1.2'
9
+
jupytext_version: 1.4.2
10
10
kernelspec:
11
11
display_name: Python 3
12
12
language: python
@@ -20,7 +20,7 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.7.3
23
+
version: 3.7.7
24
24
plotly:
25
25
description: How to set the global font, title, legend-entries, and axis-titles
26
26
in python.
@@ -34,6 +34,62 @@ jupyter:
34
34
thumbnail: thumbnail/figure-labels.png
35
35
---
36
36
37
+
### Automatic Labelling with Plotly Express
38
+
39
+
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on a variety of types of data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/).
40
+
41
+
When using Plotly Express, your axes and legend are automatically labelled, and it's easy to override the automation for a customized figure using the `labels` keyword argument. The title of your figure is up to you though!
42
+
43
+
Here's a figure with automatic labels and then the same figure with overridden labels. Note the fact that when overriding labels, the axes, legend title *and hover labels* reflect the specified labels automatically.
You can set the figure-wide font with the `layout.font` attribute, which will apply to all titles and tick labels, but this can be overridden for specific plot items like individual axes and legend titles etc. In the following figure, we set the figure-wide font to Courier New in blue, and then override this for certain parts of the figure.
When using (graph objects)[/python/graph-objects/] rather than [Plotly Express](/python/plotly-express/), you will need to explicitly label traces and axes:
92
+
37
93
```python
38
94
import plotly.graph_objects as go
39
95
@@ -54,12 +110,13 @@ fig.add_trace(go.Scatter(
54
110
55
111
fig.update_layout(
56
112
title="Plot Title",
57
-
xaxis_title="x Axis Title",
58
-
yaxis_title="y Axis Title",
113
+
xaxis_title="X Axis Title",
114
+
yaxis_title="X Axis Title",
115
+
legend_title="Legend Title",
59
116
font=dict(
60
117
family="Courier New, monospace",
61
118
size=18,
62
-
color="#7f7f7f"
119
+
color="RebeccaPurple"
63
120
)
64
121
)
65
122
@@ -90,4 +147,4 @@ fig.show()
90
147
```
91
148
92
149
#### Reference
93
-
See https://plotly.com/python/reference/#layout for more information!
150
+
See https://plotly.com/python/reference/#layout for more information!
Copy file name to clipboardExpand all lines: doc/python/legend.md
+15-3
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ jupyter:
6
6
extension: .md
7
7
format_name: markdown
8
8
format_version: '1.2'
9
-
jupytext_version: 1.3.0
9
+
jupytext_version: 1.4.2
10
10
kernelspec:
11
11
display_name: Python 3
12
12
language: python
@@ -20,7 +20,7 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.7.3
23
+
version: 3.7.7
24
24
plotly:
25
25
description: How to configure and style the legend in Plotly with Python.
26
26
display_as: file_settings
@@ -33,6 +33,18 @@ jupyter:
33
33
thumbnail: thumbnail/legends.gif
34
34
---
35
35
36
+
### Legends versus Color Bars
37
+
38
+
Plotly figures can contain two different legend-like guides: legends and color bars. Legends are used to provide a key for discrete visual variables such as [discrete colors](/python/discrete-color/) or [symbols](/python/marker-style/), whereas [color bars are used to provide a key for continuous color, and are configured differently](/python/colorscales/).
39
+
40
+
41
+
### Legends with Plotly Express
42
+
43
+
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on a variety of types of data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/).
44
+
45
+
Plotly Express will automatically construct and label a legend for any figure that uses [discrete color](/python/discrete-color/) or marker [symbols](/python/marker-style/)
46
+
47
+
36
48
#### Show Legend
37
49
38
50
By default the legend is displayed on Plotly charts with multiple traces.
@@ -434,4 +446,4 @@ fig.show()
434
446
435
447
#### Reference
436
448
437
-
See https://plotly.com/python/reference/#layout-legend for more information!
449
+
See https://plotly.com/python/reference/#layout-legend for more information!
0 commit comments