Skip to content

Commit 149c0b8

Browse files
committed
add shadow, case and lines examples
1 parent 9bf186e commit 149c0b8

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

doc/python/text-and-annotations.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,111 @@ fig.show()
446446
[scattergl](https://plotly.com/python/reference/scattergl) traces do not support all numeric font weights. Font weights up to 500 are mapped to the keyword font weight "normal", while weights above 500 are mapped to "bold".
447447

448448

449+
## Text Case
450+
451+
**New in 5.23**
452+
453+
You can configure text case using the `textfont.textcase` property. In this example, we set `textfont.textcase="upper"` to transform the text on all bars to uppercase.
454+
455+
```python
456+
import plotly.graph_objects as go
457+
from plotly import data
458+
459+
df = data.gapminder()
460+
461+
grouped = df[df.year == 2007].loc[df[df.year == 2007].groupby('continent')['lifeExp'].idxmax()]
462+
463+
fig = go.Figure(
464+
data=go.Bar(
465+
x=grouped['lifeExp'],
466+
y=grouped['continent'],
467+
text=grouped['country'],
468+
orientation='h',
469+
textfont=dict(
470+
family="sans serif",
471+
size=14,
472+
# Here we set textcase to "upper.
473+
# Set to lower" for lowercase text, or "word caps" to capitalize the first letter of each word
474+
textcase="upper"
475+
476+
)
477+
),
478+
layout=go.Layout(
479+
title_text='Country with Highest Life Expectancy per Continent, 2007',
480+
yaxis=dict(showticklabels=False)
481+
)
482+
)
483+
484+
fig.show()
485+
```
486+
487+
## Text Lines
488+
489+
**New in 5.23**
490+
491+
You can add decoration lines to text using the `textfont.lineposition` property. This property accepts `"under"`, `"over"`, and `"through"`, or a combination of these separated by a `+`.
492+
493+
```python
494+
import plotly.graph_objects as go
495+
from plotly import data
496+
497+
df = data.gapminder()
498+
499+
grouped = df[df.year == 2002].loc[df[df.year == 2002].groupby('continent')['lifeExp'].idxmax()]
500+
501+
fig = go.Figure(
502+
data=go.Bar(
503+
x=grouped['lifeExp'],
504+
y=grouped['continent'],
505+
text=grouped['country'],
506+
orientation='h',
507+
marker_color='MediumSlateBlue',
508+
textfont=dict(
509+
lineposition="under" # combine different line positions with a "+" to add more than one: "under+over"
510+
)
511+
),
512+
layout=go.Layout(
513+
title_text='Country with Highest Life Expectancy per Continent, 2002',
514+
yaxis=dict(showticklabels=False)
515+
)
516+
)
517+
518+
fig.show()
519+
```
520+
521+
## Text Shadow
522+
523+
**New in 5.23**
524+
525+
You can apply a shadow effect to text using the `textfont.shadow` property. This property accepts shadow specifications in the same format as the [text-shadow CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow).
526+
527+
```python
528+
import plotly.graph_objects as go
529+
from plotly import data
530+
531+
df = data.gapminder()
532+
533+
grouped = df[df.year == 1997].loc[df[df.year == 1997].groupby('continent')['lifeExp'].idxmax()]
534+
535+
fig = go.Figure(
536+
data=go.Bar(
537+
x=grouped['lifeExp'],
538+
y=grouped['continent'],
539+
text=grouped['country'],
540+
orientation='h',
541+
textfont=dict(
542+
shadow="1px 1px 2px pink"
543+
)
544+
),
545+
layout=go.Layout(
546+
title_text='Country with Highest Life Expectancy per Continent, 1997',
547+
yaxis=dict(showticklabels=False)
548+
)
549+
)
550+
551+
fig.show()
552+
```
553+
449554
### Styling and Coloring Annotations
450555

451556
```python

0 commit comments

Comments
 (0)