Skip to content

Commit 059433f

Browse files
committed
add plot subtitle example
1 parent b9e178d commit 059433f

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

Diff for: doc/python/figure-labels.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.16.1
9+
jupytext_version: 1.16.3
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.11
23+
version: 3.10.14
2424
plotly:
2525
description: How to set the global font, title, legend-entries, and axis-titles
2626
in python.
@@ -236,5 +236,44 @@ fig.update_layout(
236236
fig.show()
237237
```
238238

239+
### Adding a Plot Subtitle
240+
241+
*New in 5.23*
242+
243+
Add a subtitle to a plot with `layout.title.subtitle`. In the following example, we set the subtitle's `text`, and configure the `font` `color` and `size`. By default, if you don't set a font size for the subtitle, it will be `0.7` of the `title` font size.
244+
245+
```python
246+
import plotly.graph_objects as go
247+
from plotly import data
248+
249+
df = data.gapminder().query("continent == 'Europe' and (year == 1952 or year == 2002)")
250+
251+
df_pivot = df.pivot(index="country", columns="year", values="lifeExp")
252+
253+
fig = go.Figure(
254+
[
255+
go.Bar(
256+
x=df_pivot.index, y=df_pivot[1952], name="1952", marker_color="IndianRed"
257+
),
258+
go.Bar(
259+
x=df_pivot.index, y=df_pivot[2002], name="2002", marker_color="LightSalmon"
260+
),
261+
],
262+
layout=dict(
263+
title=dict(
264+
text="Life Expectancy",
265+
subtitle=dict(
266+
text="Life expectancy by European country in 1952 and in 2002",
267+
font=dict(color="gray", size=13),
268+
),
269+
)
270+
),
271+
)
272+
273+
274+
fig.show()
275+
276+
```
277+
239278
#### Reference
240279
See https://plotly.com/python/reference/layout/ for more information!

0 commit comments

Comments
 (0)