Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
animations now work + tests
  • Loading branch information
emmanuelle committed Sep 5, 2020
commit c8e852e3b58ee0be5f90b98105bbe3af0617f910
33 changes: 22 additions & 11 deletions packages/python/plotly/plotly/express/_imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ def imshow(
args["animation_frame"] = "plane"
slice_through = True

print("slice_through", slice_through)
# Default behaviour of binary_string: True for RGB images, False for 2D
if binary_string is None:
if slice_through:
Expand All @@ -382,7 +381,11 @@ def imshow(

# -------- Contrast rescaling: either minmax or infer ------------------
if contrast_rescaling is None:
contrast_rescaling = "minmax" if img.ndim == 2 else "infer"
contrast_rescaling = (
"minmax"
if (img.ndim == 2 or (img.ndim == 3 and slice_through))
else "infer"
)

# We try to set zmin and zmax only if necessary, because traces have good defaults
if contrast_rescaling == "minmax":
Expand Down Expand Up @@ -436,10 +439,8 @@ def imshow(

# For 2D+RGB data, use Image trace
elif (
img.ndim == 3
and (img.shape[-1] in [3, 4] or (slice_through and binary_string))
or (img.ndim == 2 and binary_string)
):
img.ndim >= 3 and (img.shape[-1] in [3, 4] or slice_through and binary_string)
) or (img.ndim == 2 and binary_string):
rescale_image = True # to check whether image has been modified
if zmin is not None and zmax is not None:
zmin, zmax = (
Expand All @@ -455,15 +456,16 @@ def imshow(
img, in_range=(zmin[0], zmax[0]), out_range=np.uint8
)
else:
img_rescaled = np.dstack(
img_rescaled = np.stack(
[
rescale_intensity(
img[..., ch],
in_range=(zmin[ch], zmax[ch]),
out_range=np.uint8,
)
for ch in range(img.shape[-1])
]
],
axis=-1,
)
if slice_through:
img_str = [
Expand All @@ -485,10 +487,19 @@ def imshow(
ext=binary_format,
)
]
traces = [go.Image(source=img_str_slice, name=str(i)) for i, img_str_slice in enumerate(img_str)]
traces = [
go.Image(source=img_str_slice, name=str(i))
for i, img_str_slice in enumerate(img_str)
]
else:
colormodel = "rgb" if img.shape[-1] == 3 else "rgba256"
traces = [go.Image(z=img, zmin=zmin, zmax=zmax, colormodel=colormodel)]
if slice_through:
traces = [
go.Image(z=img_slice, zmin=zmin, zmax=zmax, colormodel=colormodel)
for img_slice in img
]
else:
traces = [go.Image(z=img, zmin=zmin, zmax=zmax, colormodel=colormodel)]
layout = {}
if origin == "lower":
layout["yaxis"] = dict(autorange=True)
Expand Down Expand Up @@ -546,5 +557,5 @@ def imshow(
if labels["y"]:
fig.update_yaxes(title_text=labels["y"])
configure_animation_controls(args, go.Image, fig)
#fig.update_layout(template=args["template"], overwrite=True)
# fig.update_layout(template=args["template"], overwrite=True)
return fig
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,29 @@ def test_facet_col(facet_col, binary_string):
facet_col_wrap=facet_col_wrap,
binary_string=binary_string,
)
if facet_col is not None:
nslices = img.shape[facet_col]
ncols = int(facet_col_wrap)
nrows = nslices // ncols + 1 if nslices % ncols else nslices // ncols
nmax = ncols * nrows
assert "yaxis%d" % nmax in fig.layout
assert "yaxis%d" % (nmax + 1) not in fig.layout
assert len(fig.data) == nslices
nslices = img.shape[facet_col]
ncols = int(facet_col_wrap)
nrows = nslices // ncols + 1 if nslices % ncols else nslices // ncols
nmax = ncols * nrows
assert "yaxis%d" % nmax in fig.layout
assert "yaxis%d" % (nmax + 1) not in fig.layout
assert len(fig.data) == nslices


@pytest.mark.parametrize("animation_frame", [0, 1, 2, -1])
@pytest.mark.parametrize("binary_string", [False, True])
def test_animation_frame_grayscale(animation_frame, binary_string):
img = np.random.randint(255, size=(10, 9, 8)).astype(np.uint8)
fig = px.imshow(img, animation_frame=animation_frame, binary_string=binary_string,)
nslices = img.shape[animation_frame]
assert len(fig.frames) == nslices


@pytest.mark.parametrize("animation_frame", [0, 1, 2])
@pytest.mark.parametrize("binary_string", [False, True])
def test_animation_frame_rgb(animation_frame, binary_string):
img = np.random.randint(255, size=(10, 9, 8, 3)).astype(np.uint8)
fig = px.imshow(img, animation_frame=animation_frame, binary_string=binary_string,)
print(binary_string)
nslices = img.shape[animation_frame]
assert len(fig.frames) == nslices