-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add facet_col and animation_frame argument to imshow #2746
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
Merged
Merged
Changes from all 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 8be8ca0
WIP: add facet_col arg to imshow
emmanuelle d236bc2
animations work for grayscale images, with or without binary string
emmanuelle c8e852e
animations now work + tests
emmanuelle 12cec34
docs on facets and animations + add subplots titles
emmanuelle ab427ae
Merge branch 'master' into imshow-animation
emmanuelle 7a3a9f4
solved old unnoticed conflict
emmanuelle b689a2f
attempt to use imshow with binary strings and xarrays
emmanuelle fbb3f65
added test
emmanuelle 882810f
animation work for xarrays, still need to fix slider label
emmanuelle ba65990
added test with xarray and animations
emmanuelle cf644e5
added doc
emmanuelle 72674b7
added pooch to doc requirements
emmanuelle bd42385
Update packages/python/plotly/plotly/express/_imshow.py
emmanuelle fc2375b
Update doc/python/imshow.md
emmanuelle a431fad
remove commented-out code
emmanuelle b652039
animation + facet kinda working now, but it broke labels
emmanuelle 59c6622
added test
emmanuelle c7285a3
simplified code
emmanuelle 91c066e
simplified code
emmanuelle ac5aa1f
polished code and added doc example
emmanuelle 36b9f98
Merge branch 'imshow-animation' of https://github.com/plotly/plotly.p…
emmanuelle 8cdc6af
updated doc
emmanuelle cf1c2b9
Merge branch 'master' into imshow-animation
emmanuelle 5d1d8d8
add facet_col_spacing and facet_row_spacing
emmanuelle c27f88a
modify error message + animation_frame label
emmanuelle 502fdfd
improve code readibility
emmanuelle 135b01b
added example with sequence of images
emmanuelle 6ac3e36
typoe
emmanuelle a5a2252
label names
emmanuelle 77cb5cd
label name
emmanuelle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,7 +6,7 @@ jupyter: | |||||
extension: .md | ||||||
format_name: markdown | ||||||
format_version: '1.2' | ||||||
jupytext_version: 1.4.2 | ||||||
jupytext_version: 1.3.0 | ||||||
kernelspec: | ||||||
display_name: Python 3 | ||||||
language: python | ||||||
|
@@ -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 | ||||||
|
@@ -399,6 +399,95 @@ for compression_level in range(0, 9): | |||||
fig.show() | ||||||
``` | ||||||
|
||||||
### Exploring 3-D images, timeseries and sequences of images with `facet_col` | ||||||
|
||||||
*Introduced in plotly 4.14* | ||||||
|
||||||
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) | ||||||
img = data[20:45:2] | ||||||
fig = px.imshow(img, facet_col=0, binary_string=True, facet_col_wrap=5) | ||||||
fig.show() | ||||||
``` | ||||||
|
||||||
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. | ||||||
nicolaskruchten marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
```python | ||||||
import plotly.express as px | ||||||
import numpy as np | ||||||
from skimage import data, filters, img_as_float | ||||||
img = data.camera() | ||||||
sigmas = [1, 2, 4] | ||||||
img_sequence = [filters.gaussian(img, sigma=sigma) for sigma in sigmas] | ||||||
fig = px.imshow(np.array(img_sequence), facet_col=0, binary_string=True, | ||||||
labels={'facet_col':'sigma'}) | ||||||
# Set facet titles | ||||||
for i, sigma in enumerate(sigmas): | ||||||
fig.layout.annotations[i]['text'] = 'sigma = %d' %sigma | ||||||
fig.show() | ||||||
``` | ||||||
|
||||||
```python | ||||||
print(fig) | ||||||
``` | ||||||
|
||||||
### Exploring 3-D images and timeseries with `animation_frame` | ||||||
|
||||||
*Introduced in plotly 4.14* | ||||||
|
||||||
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.14* | ||||||
|
||||||
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`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,5 @@ pyarrow | |
cufflinks==0.17.3 | ||
kaleido | ||
umap-learn | ||
pooch | ||
wget |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.