Skip to content

Commit 2056d13

Browse files
committed
minor changes
1 parent cfac436 commit 2056d13

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

python/images.md

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jupyter:
3737

3838
#### Add a Background Image
3939

40-
In this page we explain how to add static, non-interactive images as background, logo or annotation images to a figure. For exploring image data in interactive charts, see the [tutorial on displaying image data](./imshow/).
40+
In this page we explain how to add static, non-interactive images as background, logo or annotation images to a figure. For exploring image data in interactive charts, see the [tutorial on displaying image data](/python/imshow).
4141

4242
```python
4343
import plotly.graph_objects as go
@@ -51,8 +51,7 @@ fig.add_trace(
5151
)
5252

5353
# Add images
54-
fig.update_layout(
55-
images=[
54+
fig.add_layout_image(
5655
go.layout.Image(
5756
source="https://images.plot.ly/language-icons/api-home/python-logo.png",
5857
xref="x",
@@ -64,7 +63,6 @@ fig.update_layout(
6463
sizing="stretch",
6564
opacity=0.5,
6665
layer="below")
67-
]
6866
)
6967

7068
# Set templates
@@ -117,14 +115,14 @@ fig.add_trace(
117115
)
118116

119117
# Add image
120-
fig.update_layout(
121-
images=[dict(
118+
fig.add_layout_image(
119+
dict(
122120
source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/vox.png",
123121
xref="paper", yref="paper",
124122
x=1, y=1.05,
125123
sizex=0.2, sizey=0.2,
126124
xanchor="right", yanchor="bottom"
127-
)],
125+
)
128126
)
129127

130128
# update layout properties
@@ -176,30 +174,26 @@ for (x, y), n in zip(simulated_absorptions, names):
176174
fig.add_trace(go.Scatter(x=x, y=y, name=n))
177175

178176
# Add images
179-
fig.update_layout(
180-
images=[go.layout.Image(
177+
fig.add_layout_image(
178+
go.layout.Image(
181179
source="https://raw.githubusercontent.com/michaelbabyn/plot_data/master/benzene.png",
182-
xref="paper",
183-
yref="paper",
184180
x=0.75,
185181
y=0.65,
186-
sizex=0.3,
187-
sizey=0.3,
188-
xanchor="right",
189-
yanchor="bottom"
190-
), go.layout.Image(
182+
))
183+
fig.add_layout_image(go.layout.Image(
191184
source="https://raw.githubusercontent.com/michaelbabyn/plot_data/master/naphthalene.png",
192-
xref="paper",
193-
yref="paper",
194185
x=0.9,
195186
y=0.3,
187+
)
188+
)
189+
fig.update_layout_images(dict(
190+
xref="paper",
191+
yref="paper",
196192
sizex=0.3,
197193
sizey=0.3,
198194
xanchor="right",
199195
yanchor="bottom"
200-
)
201-
]
202-
)
196+
))
203197

204198
# Add annotations
205199
fig.update_layout(
@@ -282,8 +276,8 @@ fig.update_yaxes(
282276
)
283277

284278
# Add image
285-
fig.update_layout(
286-
images=[go.layout.Image(
279+
fig.add_layout_image(
280+
go.layout.Image(
287281
x=0,
288282
sizex=img_width * scale_factor,
289283
y=img_height * scale_factor,
@@ -293,7 +287,7 @@ fig.update_layout(
293287
opacity=1.0,
294288
layer="below",
295289
sizing="stretch",
296-
source="https://raw.githubusercontent.com/michaelbabyn/plot_data/master/bridge.jpg")]
290+
source="https://raw.githubusercontent.com/michaelbabyn/plot_data/master/bridge.jpg")
297291
)
298292

299293
# Configure other layout

python/imshow.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ jupyter:
3737
v4upgrade: true
3838
---
3939

40+
This tutorial shows how to display and explore image data. If you would like
41+
instead a logo or static image, use `go.layout.Image` as explained
42+
[here](/python/images).
43+
4044
### Displaying RBG image data with px.imshow
4145

4246
`px.imshow` displays multichannel (RGB) or single-channel ("grayscale") image data.
@@ -73,7 +77,7 @@ fig.show()
7377

7478
### Display single-channel 2D image as grayscale
7579

76-
For a 2D image, `px.imshows` uses a colorscale to map scalar data to colors. The default colorscale is `gray`, ie grayscale images.
80+
For a 2D image, `px.imshow` uses a colorscale to map scalar data to colors. The default colorscale is `gray`, ie grayscale images.
7781

7882
```python
7983
import plotly.express as px
@@ -85,7 +89,6 @@ fig.show()
8589

8690
### Choose the colorscale to display a single-channel image
8791

88-
For a 2D image, `px.imshows` uses a colorscale to map scalar data to colors. The default colorscale is `gray`, ie grayscale images.
8992

9093
```python
9194
import plotly.express as px
@@ -97,9 +100,9 @@ fig.show()
97100

98101
### Display multichannel image data with go.Image
99102

100-
It is also possible to use the `go.Image` trace from the low-level `graph_objects` API in order to display image data. Note that `go.Image` only accepts multichannel images. For single images, use [`go.Heatmap`](https://plot.ly/python/heatmaps/).
103+
It is also possible to use the `go.Image` trace from the low-level `graph_objects` API in order to display image data. Note that `go.Image` only accepts multichannel images. For single images, use [`go.Heatmap`](/python/heatmaps).
101104

102-
Note that the `go.Image` trace is different from the `go.layout.Image` class, which can be used for [adding background images or logos to figures](./images/).
105+
Note that the `go.Image` trace is different from the `go.layout.Image` class, which can be used for [adding background images or logos to figures](/python/images).
103106

104107
```python
105108
import plotly.graph_objects as go

0 commit comments

Comments
 (0)