Skip to content

Commit 63a4dc9

Browse files
committed
use rgba256 colormodel
1 parent 4db5fe4 commit 63a4dc9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/python/plotly/plotly/express/_imshow.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ def _array_to_b64str(img, backend="pil", compression=4):
7979
return base64_string
8080

8181

82-
def _vectorize_zvalue(z):
82+
def _vectorize_zvalue(z, mode='max'):
83+
alpha = 255 if mode == 'max' else 0
8384
if z is None:
8485
return z
8586
elif np.isscalar(z):
86-
return [z] * 3 + [255]
87+
return [z] * 3 + [alpha]
8788
elif len(z) == 1:
88-
return list(z) * 3 + [255]
89+
return list(z) * 3 + [alpha]
8990
elif len(z) == 3:
90-
return list(z) + [255]
91+
return list(z) + [alpha]
9192
elif len(z) == 4:
9293
return z
9394
else:
@@ -382,7 +383,7 @@ def imshow(
382383
elif img.ndim == 3 and img.shape[-1] in [3, 4] or (img.ndim == 2 and binary_string):
383384
rescale_image = True # to check whether image has been modified
384385
if zmin is not None and zmax is not None:
385-
zmin, zmax = _vectorize_zvalue(zmin), _vectorize_zvalue(zmax)
386+
zmin, zmax = _vectorize_zvalue(zmin, mode='min'), _vectorize_zvalue(zmax, mode='max')
386387
if binary_string:
387388
if zmin is None and zmax is None: # no rescaling, faster
388389
img_rescaled = img
@@ -392,6 +393,7 @@ def imshow(
392393
img, in_range=(zmin[0], zmax[0]), out_range=np.uint8
393394
)
394395
else:
396+
print(zmin, zmax)
395397
img_rescaled = np.dstack(
396398
[
397399
rescale_intensity(
@@ -409,7 +411,7 @@ def imshow(
409411
)
410412
trace = go.Image(source=img_str)
411413
else:
412-
colormodel = "rgb" if img.shape[-1] == 3 else "rgba"
414+
colormodel = "rgb" if img.shape[-1] == 3 else "rgba256"
413415
trace = go.Image(z=img, zmin=zmin, zmax=zmax, colormodel=colormodel)
414416
layout = {}
415417
if origin == "lower":

0 commit comments

Comments
 (0)