Skip to content

Commit 0cecbd6

Browse files
committed
do not do anything when origin='lower' because the JS already takes care of this with source
1 parent 91f608e commit 0cecbd6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,20 @@ def imshow(
307307
if aspect is None:
308308
aspect = "equal"
309309

310-
# Set the value of binary_string
310+
# --- Set the value of binary_string (forbidden for pandas)
311311
if isinstance(img, pd.DataFrame):
312312
if binary_string:
313313
raise ValueError("Binary strings cannot be used with pandas arrays")
314-
has_nans = True
314+
is_dataframe = True
315315
else:
316-
has_nans = False
316+
is_dataframe = False
317317

318318
# --------------- Starting from here img is always a numpy array --------
319319
img = np.asanyarray(img)
320320

321321
# Default behaviour of binary_string: True for RGB images, False for 2D
322322
if binary_string is None:
323-
binary_string = img.ndim >= 3 and not has_nans
323+
binary_string = img.ndim >= 3 and not is_dataframe
324324

325325
# Cast bools to uint8 (also one byte)
326326
if img.dtype == np.bool:
@@ -329,16 +329,21 @@ def imshow(
329329
if range_color is not None:
330330
zmin = range_color[0]
331331
zmax = range_color[1]
332+
333+
# -------- Contrast rescaling: either minmax or infer ------------------
332334
if contrast_rescaling is None:
333335
contrast_rescaling = "minmax" if img.ndim == 2 else "infer"
334336

337+
# We try to set zmin and zmax only if necessary, because traces have good defaults
335338
if contrast_rescaling == "minmax":
339+
# When using binary_string and minmax we need to set zmin and zmax to rescale the image
336340
if (zmin is not None or binary_string) and zmax is None:
337341
zmax = img.max()
338342
if (zmax is not None or binary_string) and zmin is None:
339343
zmin = img.min()
340344
else:
341-
if zmax is None and (img.dtype != np.uint8 or img.ndim == 2):
345+
# For uint8 data and infer we let zmin and zmax to be None if passed as None
346+
if zmax is None and img.dtype != np.uint8:
342347
zmax = _infer_zmax_from_type(img)
343348
if zmin is None and zmax is not None:
344349
zmin = 0
@@ -395,8 +400,6 @@ def imshow(
395400
for ch in range(img.shape[-1])
396401
]
397402
)
398-
if origin == "lower":
399-
img_rescaled = img_rescaled[::-1]
400403
img_str = _array_to_b64str(
401404
img_rescaled,
402405
backend=binary_backend,

0 commit comments

Comments
 (0)