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
+91-12Lines changed: 91 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -677,12 +677,12 @@ import plotly.graph_objects as go
677
677
fig = go.Figure()
678
678
679
679
fig.add_shape(
680
-
type="rect",
681
-
fillcolor='turquoise',
682
-
x0=1,
683
-
y0=1,
684
-
x1=2,
685
-
y1=3,
680
+
type="rect",
681
+
fillcolor='turquoise',
682
+
x0=1,
683
+
y0=1,
684
+
x1=2,
685
+
y1=3,
686
686
label=dict(text="Text in rectangle")
687
687
)
688
688
fig.add_shape(
@@ -701,8 +701,8 @@ fig.show()
701
701
702
702
#### Styling Text Labels
703
703
704
-
Use the `font` property to configure the `color`, `size`, and `family` of the label font.
705
-
In this example, we change the label color of the first rectangle to "DarkOrange", set the size of the text above the line to 20, and change the font family and set the font size on the second rectangle.
704
+
Use the `font` property to configure the `color`, `size`, and `family` of the label font.
705
+
In this example, we change the label color of the first rectangle to "DarkOrange", set the size of the text above the line to 20, and change the font family and set the font size on the second rectangle.
706
706
707
707
```python
708
708
import plotly.graph_objects as go
@@ -776,7 +776,7 @@ fig.add_shape(
776
776
777
777
fig.add_shape(
778
778
type="line",
779
-
line_color="MediumSlateBlue",
779
+
line_color="MediumSlateBlue",
780
780
x0=3,
781
781
y0=2,
782
782
x1=5,
@@ -870,10 +870,10 @@ fig.show()
870
870
871
871
#### Setting Label Anchors
872
872
873
-
`xanchor` sets a label's horizontal positional anchor and `yanchor` sets its vertical position anchor.
873
+
`xanchor` sets a label's horizontal positional anchor and `yanchor` sets its vertical position anchor.
874
874
Use `xanchor` to bind the `textposition` to the "left", "center" or "right" of the label text and `yanchor` to bind `textposition` to the "top", "middle" or "bottom" of the label text.
875
875
876
-
In this example, `yanchor`is set to "top", instead of the default of "bottom" for lines, meaning the text displays below the line.
876
+
In this example, `yanchor`is set to "top", instead of the default of "bottom" for lines, meaning the text displays below the line.
877
877
878
878
879
879
```python
@@ -930,7 +930,7 @@ Use `texttemplate` to add text with variables to shapes. You have access to raw
930
930
931
931
`texttemplate` supports d3 number and date formatting.
932
932
933
-
Add a variable with "%{variable}". This example adds the raw variables `x0` and `y0` to a rectangle and shows the calculated variables `height`, `slope`, `length`, and `width` on three other shapes.
933
+
Add a variable with "%{variable}". This example adds the raw variables `x0` and `y0` to a rectangle and shows the calculated variables `height`, `slope`, `length`, and `width` on three other shapes.
934
934
935
935
```python
936
936
import plotly.graph_objects as go
@@ -1017,6 +1017,85 @@ fig = go.Figure(
1017
1017
)
1018
1018
1019
1019
1020
+
fig.show(
1021
+
config={
1022
+
"modeBarButtonsToAdd": [
1023
+
"drawline",
1024
+
]
1025
+
}
1026
+
)
1027
+
```
1028
+
1029
+
#### Shapes in the Legend
1030
+
1031
+
*New in 5.16*
1032
+
1033
+
You can add a shape to the legend by setting `showlegend=True` on the shape. In this example, we add the second shape to the legend. The name that appears for the shape in the legend is the shape's `name` if it is provided. If no `name` is provided, the shape label's `text` is used. If neither is provided, the legend item appears as "shape \<shape number>". For example, "shape 1".
0 commit comments