Skip to content

Commit 9dc893d

Browse files
committed
Update shapes.md
1 parent 55597ab commit 9dc893d

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

doc/python/shapes.md

Lines changed: 61 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.3
9+
jupytext_version: 1.19.1
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.14
23+
version: 3.14.3
2424
plotly:
2525
description: How to make SVG shapes in python. Examples of lines, circle, rectangle,
2626
and path.
@@ -488,6 +488,65 @@ fig.update_layout(
488488
fig.show()
489489
```
490490

491+
#### Shapes Spanning Subplots
492+
493+
*New in 6.6*
494+
495+
You can create shapes that span multiple subplots by passing an array of axis references to `xref` and `yref`. Each element in the array specifies which axis the corresponding coordinate refers to. For example, in the following code, with `xref=["x", "x2"]`, `x0` refers to the `x` axis and `x1` refers to the `x2` axis.
496+
497+
```python
498+
import plotly.graph_objects as go
499+
from plotly.subplots import make_subplots
500+
501+
fig = make_subplots(rows=1, cols=2)
502+
503+
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6], mode="markers", marker=dict(size=10)), row=1, col=1)
504+
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[6, 5, 4], mode="markers", marker=dict(size=10)), row=1, col=2)
505+
506+
fig.add_shape(
507+
type="rect",
508+
xref=["x", "x2"], # x0 uses the x-axis from subplot 1 ("x"), while x1 uses the x-axis from subplot 2 ("x2")
509+
yref=["y", "y2"], # y0 uses the y-axis from subplot 1 ("y"), while y1 uses the y-axis from subplot 2 ("y2")
510+
x0=2, y0=4.5,
511+
x1=3, y1=5.5,
512+
fillcolor="rgba(255, 0, 0, 0.2)",
513+
line=dict(color="red", width=2),
514+
)
515+
516+
fig.show()
517+
```
518+
519+
For `path` shapes, the array must have one entry for each coordinate in the path string. Each coordinate in the path maps to the corresponding element in the `xref`/`yref` array, in order.
520+
521+
```python
522+
import plotly.graph_objects as go
523+
from plotly.subplots import make_subplots
524+
525+
fig = make_subplots(rows=1, cols=2)
526+
527+
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3], mode="markers"), row=1, col=1)
528+
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[3, 2, 1], mode="markers"), row=1, col=2)
529+
530+
# Chevron shape spanning both subplots
531+
# Path coordinates map to axis refs in order:
532+
# M 2.5 1.5 -> xref[0]=x, yref[0]=y (start in subplot 1)
533+
# L 1.5 2 -> xref[1]=x2, yref[1]=y2 (tip in subplot 2)
534+
# L 2.5 2.5 -> xref[2]=x, yref[2]=y (end in subplot 1)
535+
536+
fig.add_shape(
537+
type="path",
538+
path="M 2.5 1.5 L 1.5 2 L 2.5 2.5",
539+
xref=["x", "x2", "x"],
540+
yref=["y", "y2", "y"],
541+
line=dict(color="purple", width=3),
542+
)
543+
544+
fig.show()
545+
```
546+
547+
**Note:** When using arrays with `xref` and `yref`, `xsizemode="pixel"` and `ysizemode="pixel"` are not supported.
548+
549+
491550
#### Adding the Same Shapes to Multiple Subplots
492551
The same shape can be added to multiple facets by using the `'all'`
493552
keyword in the `row` and `col` arguments. For example

0 commit comments

Comments
 (0)