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/shapes.md
+87-1Lines changed: 87 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.10.9
23
+
version: 3.8.8
24
24
plotly:
25
25
description: How to make SVG shapes in python. Examples of lines, circle, rectangle,
26
26
and path.
@@ -913,5 +913,91 @@ fig.add_shape(
913
913
fig.show()
914
914
```
915
915
916
+
#### Variables in Shape Label Text
917
+
918
+
*New in 5.15*
919
+
920
+
Use `texttemplate` to add text with variables to shapes. `texttemplate` uses d3 number and date formatting and supports raw variables, which use the raw data from the shape definition, and some calculated variables.
921
+
922
+
This example adds the raw variables `x0` and `y0` to a rectangle and shows the calculated variables `height`, `slope`, and `width`on three other shapes.
923
+
924
+
For a complete list of available variables, see the [Shape Reference Docs](https://plotly.com/python/reference/layout/shapes/).
925
+
926
+
927
+
```python
928
+
import plotly.graph_objects as go
929
+
930
+
fig = go.Figure()
931
+
932
+
fig.add_shape(
933
+
type="rect",
934
+
fillcolor="MediumSlateBlue",
935
+
x0=-0.5,
936
+
y0=-0.5,
937
+
x1=1,
938
+
y1=1,
939
+
label=dict(
940
+
texttemplate="x0 is %{x0:.3f}, y0 is %{y0:.3f}", font=dict(color="DarkOrange")
Use `texttemplate` to add text with variables to new shapes drawn on the graph. This example figure is configured to allow the user to draw lines and automatically labels each line with its slope. Select **Draw line** in the modebar to try it out.
0 commit comments