Skip to content

Commit 52e0469

Browse files
committed
Update horizontal-vertical-shapes.md
1 parent 3b3f98a commit 52e0469

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

doc/python/horizontal-vertical-shapes.md

+41
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,47 @@ fig.add_vrect(x0="2018-09-24", x1="2018-12-18", row="all", col=1,
139139
fillcolor="green", opacity=0.25, line_width=0)
140140
fig.show()
141141
```
142+
#### Text Labels on Shapes
143+
144+
*New in 5.14*
145+
146+
[Text labels on shapes](/python/shapes/#addingtextlabelstoshapes), introduced in version 5.14, is now the recommended way to add shapes with text. The above examples using `add_hline`, `add_vrect`, `add_hrect`, and `add_vline` that add annotations can be rewritten to use `label`.
147+
148+
149+
```python
150+
import plotly.express as px
151+
152+
df = px.data.stocks(indexed=True)
153+
fig = px.line(df)
154+
fig.add_hline(
155+
y=1,
156+
line_dash="dot",
157+
label=dict(
158+
text="Jan 1 2018 Baseline",
159+
textposition="end",
160+
font=dict(size=20, color="blue"),
161+
yanchor="top",
162+
),
163+
)
164+
fig.add_vrect(
165+
x0="2018-09-24",
166+
x1="2018-12-18",
167+
label=dict(
168+
text="Decline",
169+
textposition="top center",
170+
font=dict(size=20, family="Times New Roman"),
171+
),
172+
fillcolor="green",
173+
opacity=0.25,
174+
line_width=0,
175+
)
176+
fig.show()
177+
178+
```
179+
180+
With [text labels on shapes](/python/shapes/#addingtextlabelstoshapes), you can also add text labels to shapes other than lines and rectangles, and can they can be added to shapes drawn by the user.
181+
182+
142183
### Reference
143184

144185
More details are available about [layout shapes](/python/shapes/) and [annotations](/python/text-and-annotations).

0 commit comments

Comments
 (0)