Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c5126c

Browse files
Improved domain referenced objects docs
In particular, added example for layout images, showing how their position can reference an axis domain.
1 parent be7eb0f commit 0c5126c

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

doc/python/horizontal-vertical-shapes.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ jupyter:
3434

3535
### Horizontal and Vertical Lines and Boxes (Autoshapes) in Plotly.py
3636

37+
*introduced in plotly 4.12*
38+
3739
Horizontal and vertical lines and rectangles (autoshapes) that span an entire
3840
plot can be added via the `add_hline`, `add_vline`, `add_hrect`, and `add_vrect`
39-
methods of `plotly.graph_objects.Figure`. These shapes are fixed to the
40-
endpoints of one axis, regardless of the range of the plot, and fixed to data
41-
coordinates on the other axis. For example
41+
methods of `plotly.graph_objects.Figure`. Shapes added with these methods are
42+
added as [layout shapes](/python/shapes) (as shown when doing `print(fig)`, for
43+
example). These shapes are fixed to the endpoints of one axis, regardless of the
44+
range of the plot, and fixed to data coordinates on the other axis. The
45+
following shows some possibilities, try panning and zooming the resulting figure
46+
to see how the shapes stick to some axes:
4247

4348

4449
```python
@@ -59,7 +64,7 @@ fig.add_vrect(x0=5.5, x1=6.5, line_color="purple")
5964
# Add a horizontal rectangle that spans the entire x axis
6065
# intersecting the y axis at 2.5 and 4
6166
fig.add_hrect(y0=2.5, y1=4, line_color="orange")
62-
# (try dragging the plot around)
67+
# (try panning and zooming the plot)
6368
fig.show()
6469
```
6570

@@ -88,8 +93,8 @@ example.
8893

8994
#### Adding Text Annotations to Autoshapes
9095

91-
Text can be added to an autoshape using the `annotation` keyword. Using the
92-
above example:
96+
Text [annotations](/python/text-and-annotations) can be added to an autoshape
97+
using the `annotation` keyword. Using the above example:
9398
```python
9499
import plotly.express as px
95100
import plotly.graph_objects as go

doc/python/images.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,41 @@ fig.show(config={'modeBarButtonsToAdd':['drawline',
360360
```
361361

362362

363-
### Images Placed Relative to the Axes
363+
### Images Placed Relative to Axes
364+
365+
Using `xref='x domain'` or `yref='y domain'`, images can be placed relative to
366+
axes. As an example, the following shows how to put an image in the top corner
367+
of a subplot (try panning and zooming the resulting figure):
368+
369+
```python
370+
import plotly.express as px
371+
372+
df = px.data.iris()
373+
fig = px.scatter(df, x="sepal_length", y="sepal_width", facet_col="species")
374+
# sources of images
375+
sources = [
376+
"https://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Iris_setosa_var._setosa_%282595031014%29.jpg/360px-Iris_setosa_var._setosa_%282595031014%29.jpg",
377+
"https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Iris_versicolor_quebec_1.jpg/320px-Iris_versicolor_quebec_1.jpg",
378+
"https://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/Iris_virginica_2.jpg/480px-Iris_virginica_2.jpg",
379+
]
380+
# add images
381+
for col, src in enumerate(sources):
382+
fig.add_layout_image(
383+
row=1,
384+
col=col + 1,
385+
source=src,
386+
xref="x domain",
387+
yref="y domain",
388+
x=1,
389+
y=1,
390+
xanchor="right",
391+
yanchor="top",
392+
sizex=0.2,
393+
sizey=0.2,
394+
)
395+
396+
fig.show()
397+
```
364398

365399
#### Reference
366400
See https://plotly.com/python/reference/layout/images/ for more information and chart attribute options!

0 commit comments

Comments
 (0)