Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add facet_col and animation_frame argument to imshow #2746

Merged
merged 31 commits into from Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
afb5c4d
use init_figure from main px core
emmanuelle Sep 3, 2020
8be8ca0
WIP: add facet_col arg to imshow
emmanuelle Sep 3, 2020
d236bc2
animations work for grayscale images, with or without binary string
emmanuelle Sep 4, 2020
c8e852e
animations now work + tests
emmanuelle Sep 5, 2020
12cec34
docs on facets and animations + add subplots titles
emmanuelle Sep 6, 2020
ab427ae
Merge branch 'master' into imshow-animation
emmanuelle Sep 7, 2020
7a3a9f4
solved old unnoticed conflict
emmanuelle Sep 7, 2020
b689a2f
attempt to use imshow with binary strings and xarrays
emmanuelle Sep 7, 2020
fbb3f65
added test
emmanuelle Sep 7, 2020
882810f
animation work for xarrays, still need to fix slider label
emmanuelle Sep 7, 2020
ba65990
added test with xarray and animations
emmanuelle Sep 7, 2020
cf644e5
added doc
emmanuelle Sep 7, 2020
72674b7
added pooch to doc requirements
emmanuelle Sep 7, 2020
bd42385
Update packages/python/plotly/plotly/express/_imshow.py
emmanuelle Sep 8, 2020
fc2375b
Update doc/python/imshow.md
emmanuelle Sep 8, 2020
a431fad
remove commented-out code
emmanuelle Sep 9, 2020
b652039
animation + facet kinda working now, but it broke labels
emmanuelle Sep 17, 2020
59c6622
added test
emmanuelle Sep 17, 2020
c7285a3
simplified code
emmanuelle Sep 17, 2020
91c066e
simplified code
emmanuelle Sep 17, 2020
ac5aa1f
polished code and added doc example
emmanuelle Sep 17, 2020
36b9f98
Merge branch 'imshow-animation' of https://github.com/plotly/plotly.p…
emmanuelle Sep 17, 2020
8cdc6af
updated doc
emmanuelle Nov 17, 2020
cf1c2b9
Merge branch 'master' into imshow-animation
emmanuelle Nov 18, 2020
5d1d8d8
add facet_col_spacing and facet_row_spacing
emmanuelle Nov 24, 2020
c27f88a
modify error message + animation_frame label
emmanuelle Nov 24, 2020
502fdfd
improve code readibility
emmanuelle Nov 24, 2020
135b01b
added example with sequence of images
emmanuelle Nov 24, 2020
6ac3e36
typoe
emmanuelle Nov 24, 2020
a5a2252
label names
emmanuelle Nov 27, 2020
77cb5cd
label name
emmanuelle Nov 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 70 additions & 2 deletions doc/python/imshow.md
Expand Up @@ -6,7 +6,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.4.2
jupytext_version: 1.7.1
kernelspec:
display_name: Python 3
language: python
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.7.7
version: 3.7.3
plotly:
description: How to display image data in Python with Plotly.
display_as: scientific
Expand Down Expand Up @@ -399,6 +399,74 @@ for compression_level in range(0, 9):
fig.show()
```

### Exploring 3-D images and timeseries with `facet_col`

*Introduced in plotly 4.13*

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`.

It is recommended to use `binary_string=True` for facetted plots of images in order to keep a small figure size and a short rendering time.

See the [tutorial on facet plots](/python/facet-plots/) for more information on creating and styling facet plots.

```python
import plotly.express as px
from skimage import io
from skimage.data import image_fetcher
path = image_fetcher.fetch('data/cells.tif')
data = io.imread(path)
mkcor marked this conversation as resolved.
Show resolved Hide resolved
img = data[20:45:2]
fig = px.imshow(img, facet_col=0, binary_string=True, facet_col_wrap=5)
fig.show()
```

### Exploring 3-D images and timeseries with `animation_frame`

*Introduced in plotly 4.13*

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.

```python
import plotly.express as px
from skimage import io
from skimage.data import image_fetcher
path = image_fetcher.fetch('data/cells.tif')
data = io.imread(path)
img = data[25:40]
fig = px.imshow(img, animation_frame=0, binary_string=True)
fig.show()
```

### Animations of xarray datasets

*Introduced in plotly 4.11*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*Introduced in plotly 4.11*
*Introduced in plotly 4.13*


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.

```python
import plotly.express as px
import xarray as xr
# Load xarray from dataset included in the xarray tutorial
ds = xr.tutorial.open_dataset('air_temperature').air[:20]
fig = px.imshow(ds, animation_frame='time', zmin=220, zmax=300, color_continuous_scale='RdBu_r')
fig.show()
```

### Combining animations and facets

It is possible to view 4-dimensional datasets (for example, 3-D images evolving with time) using a combination of `animation_frame` and `facet_col`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It is possible to view 4-dimensional datasets (for example, 3-D images evolving with time) using a combination of `animation_frame` and `facet_col`.
It is possible to view four-dimensional datasets (for example, 3-D images evolving with time) using a combination of `animation_frame` and `facet_col`.

(because above text reads 'three-dimensional')


```python
import plotly.express as px
from skimage import io
from skimage.data import image_fetcher
path = image_fetcher.fetch('data/cells.tif')
data = io.imread(path)
data = data.reshape((15, 4, 256, 256))[5:]
fig = px.imshow(data, animation_frame=0, facet_col=1, binary_string=True)
fig.show()
```

#### Reference

See https://plotly.com/python/reference/image/ for more information and chart attribute options!
1 change: 1 addition & 0 deletions doc/requirements.txt
Expand Up @@ -28,4 +28,5 @@ pyarrow
cufflinks==0.17.3
kaleido
umap-learn
pooch
wget