Skip to content

Commit 135b01b

Browse files
committed
added example with sequence of images
1 parent 502fdfd commit 135b01b

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

Diff for: doc/python/imshow.md

+26-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.7.1
9+
jupytext_version: 1.3.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -399,9 +399,9 @@ for compression_level in range(0, 9):
399399
fig.show()
400400
```
401401

402-
### Exploring 3-D images and timeseries with `facet_col`
402+
### Exploring 3-D images, timeseries and sequences of images with `facet_col`
403403

404-
*Introduced in plotly 4.13*
404+
*Introduced in plotly 4.14*
405405

406406
For three-dimensional image datasets, obtained for example by MRI or CT in medical imaging, one can explore the dataset by representing its different planes as facets. The `facet_col` argument specifies along which axis the image is sliced through to make the facets. With `facet_col_wrap`, one can set the maximum number of columns. For image datasets passed as xarrays, it is also possible to specify the axis by its name (label), thus passing a string to `facet_col`.
407407

@@ -420,9 +420,30 @@ fig = px.imshow(img, facet_col=0, binary_string=True, facet_col_wrap=5)
420420
fig.show()
421421
```
422422

423+
Facets can also be used to represent several images of equal shape, like in the example below where different values of the blurring parameter of a Gaussian filter are compared.
424+
425+
```python
426+
import plotly.express as px
427+
import numpy as np
428+
from skimage import data, filters, img_as_float
429+
img = data.camera()
430+
sigmas = [1, 2, 4]
431+
img_sequence = [filters.gaussian(img, sigma=sigma) for sigma in sigmas]
432+
fig = px.imshow(np.array(img_sequence), facet_col=0, binary_string=True,
433+
labels={'facet_col':'sigma'})
434+
# Set facet titles
435+
for sigma in sigmas:
436+
fig.layout.annotations[i]['text'] = 'sigma = %d' %sigma
437+
fig.show()
438+
```
439+
440+
```python
441+
print(fig)
442+
```
443+
423444
### Exploring 3-D images and timeseries with `animation_frame`
424445

425-
*Introduced in plotly 4.13*
446+
*Introduced in plotly 4.14*
426447

427448
For three-dimensional image datasets, obtained for example by MRI or CT in medical imaging, one can explore the dataset by sliding through its different planes in an animation. The `animation_frame` argument of `px.imshow` sets the axis along which the 3-D image is sliced in the animation.
428449

@@ -439,7 +460,7 @@ fig.show()
439460

440461
### Animations of xarray datasets
441462

442-
*Introduced in plotly 4.11*
463+
*Introduced in plotly 4.14*
443464

444465
For xarray datasets, one can pass either an axis number or an axis name to `animation_frame`. Axis names and coordinates are automatically used for the labels, ticks and animation controls of the figure.
445466

Diff for: packages/python/plotly/plotly/express/_imshow.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,9 @@ def imshow(
519519
# Now build figure
520520
col_labels = []
521521
if facet_col is not None:
522-
slice_label = "slice" if labels.get("facet") is None else labels["facet"]
522+
slice_label = (
523+
"slice" if labels.get("facet_col") is None else labels["facet_col"]
524+
)
523525
col_labels = ["%s = %d" % (slice_label, i) for i in facet_slices]
524526
fig = init_figure(args, "xy", [], nrows, ncols, col_labels, [])
525527
for attr_name in ["height", "width"]:

0 commit comments

Comments
 (0)