-
-
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
Changes from 13 commits
afb5c4d
8be8ca0
d236bc2
c8e852e
12cec34
ab427ae
7a3a9f4
b689a2f
fbb3f65
882810f
ba65990
cf644e5
72674b7
bd42385
fc2375b
a431fad
b652039
59c6622
c7285a3
91c066e
ac5aa1f
36b9f98
8cdc6af
cf1c2b9
5d1d8d8
c27f88a
502fdfd
135b01b
6ac3e36
a5a2252
77cb5cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,9 +399,73 @@ for compression_level in range(0, 9): | |||||
| fig.show() | ||||||
| ``` | ||||||
|
|
||||||
| ### Exploring 3-D images and timeseries with `facet_col` | ||||||
|
|
||||||
| *Introduced in plotly 4.11* | ||||||
|
|
||||||
| 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 axes 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 give an axis name as a string for `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[25:40] | ||||||
| fig = px.imshow(img, facet_col=0, binary_string=True, facet_col_wrap=5, height=700) | ||||||
| fig.show() | ||||||
| ``` | ||||||
|
|
||||||
| ```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, facet_col=0, binary_string=True, facet_col_wrap=5) | ||||||
| # To have square facets one needs to unmatch axes | ||||||
| fig.update_xaxes(matches=None) | ||||||
| fig.update_yaxes(matches=None) | ||||||
| fig.show() | ||||||
| ``` | ||||||
|
|
||||||
| ### Exploring 3-D images and timeseries with `animation_frame` | ||||||
|
|
||||||
| *Introduced in plotly 4.11* | ||||||
|
|
||||||
| 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* | ||||||
|
||||||
| *Introduced in plotly 4.11* | |
| *Introduced in plotly 4.13* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,3 +28,4 @@ pyarrow | |
| cufflinks==0.17.3 | ||
| kaleido | ||
| umap-learn | ||
| pooch | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||
| import plotly.graph_objs as go | ||||||
| from _plotly_utils.basevalidators import ColorscaleValidator | ||||||
| from ._core import apply_default_cascade | ||||||
| from ._core import apply_default_cascade, init_figure, configure_animation_controls | ||||||
| from io import BytesIO | ||||||
| import base64 | ||||||
| from .imshow_utils import rescale_intensity, _integer_ranges, _integer_types | ||||||
|
|
@@ -133,6 +133,9 @@ def imshow( | |||||
| labels={}, | ||||||
| x=None, | ||||||
| y=None, | ||||||
| animation_frame=None, | ||||||
| facet_col=None, | ||||||
| facet_col_wrap=None, | ||||||
nicolaskruchten marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| color_continuous_scale=None, | ||||||
| color_continuous_midpoint=None, | ||||||
| range_color=None, | ||||||
|
|
@@ -186,6 +189,14 @@ def imshow( | |||||
| their lengths must match the lengths of the second and first dimensions of the | ||||||
| img argument. They are auto-populated if the input is an xarray. | ||||||
|
|
||||||
| facet_col: int, optional (default None) | ||||||
| axis number along which the image array is slices to create a facetted plot. | ||||||
|
||||||
| axis number along which the image array is slices to create a facetted plot. | |
| axis along which the image array is sliced to create a facetted plot. |
I'm not entirely positive about my suggestion to remove 'number' in 'axis number'... From https://numpy.org/doc/stable/glossary.html, it looks like conventional terminology would be just 'axis' (as in 'axis 0' and 'axis 1'); I was tempted by 'axis index' but this would be confusing with dataframes (as in, 'index' vs 'columns'). Maybe 'axis number' is conventional terminology after all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
axis is fine indeed. It could also be "axis position" (as in the docstring of np.moveaxis). We can also ask other opinions, what do you think about the terminology @nicolaskruchten ?
emmanuelle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3- or 4-D ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a bit odd to have layout and layout_patch here... it was odd before I guess but might be worth looking at merging them together earlier?
Uh oh!
There was an error while loading. Please reload this page.