Skip to content

Commit aab5efe

Browse files
committed
add numeric font weight example
1 parent b8d67c5 commit aab5efe

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

doc/python/text-and-annotations.md

Lines changed: 53 additions & 2 deletions
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.2
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.0
2424
plotly:
2525
description: How to add text labels and annotations to plots in python.
2626
display_as: file_settings
@@ -395,6 +395,57 @@ fig.show()
395395

396396
```
397397

398+
## Numeric Font Weight
399+
400+
*New in 5.23*
401+
402+
In the previous example, we set a `font-weight` using a keyword value. You can also set `font-weight` using a numeric value.
403+
404+
The font weights available depend on the `font-family` that is set. The `font-weight`
405+
If you set a `font-weight` that isn't available for a particular `font-family`, the weight will be rounded to the nearest available value.
406+
407+
In the following example,
408+
409+
410+
```python
411+
import plotly.graph_objects as go
412+
from plotly import data
413+
414+
df = data.medals_wide()
415+
416+
fig = go.Figure(
417+
data=[
418+
go.Bar(
419+
x=df.nation,
420+
y=df.gold,
421+
name="Gold",
422+
marker=dict(color="Gold"),
423+
text="Gold",
424+
textfont=dict(weight=400, size=17),
425+
),
426+
go.Bar(
427+
x=df.nation,
428+
y=df.silver,
429+
name="Silver",
430+
marker=dict(color="MediumTurquoise"),
431+
text="Silver",
432+
textfont=dict(weight=600, size=17),
433+
),
434+
go.Bar(
435+
x=df.nation,
436+
y=df.bronze,
437+
name="Bronze",
438+
marker=dict(color="LightGreen"),
439+
text="Bronze",
440+
textfont=dict(weight=1000, size=17),
441+
),
442+
],
443+
layout=dict(barcornerradius=15, showlegend=False),
444+
)
445+
446+
fig.show()
447+
```
448+
398449
### Styling and Coloring Annotations
399450

400451
```python

0 commit comments

Comments
 (0)