@@ -307,20 +307,20 @@ def imshow(
307
307
if aspect is None :
308
308
aspect = "equal"
309
309
310
- # Set the value of binary_string
310
+ # --- Set the value of binary_string (forbidden for pandas)
311
311
if isinstance (img , pd .DataFrame ):
312
312
if binary_string :
313
313
raise ValueError ("Binary strings cannot be used with pandas arrays" )
314
- has_nans = True
314
+ is_dataframe = True
315
315
else :
316
- has_nans = False
316
+ is_dataframe = False
317
317
318
318
# --------------- Starting from here img is always a numpy array --------
319
319
img = np .asanyarray (img )
320
320
321
321
# Default behaviour of binary_string: True for RGB images, False for 2D
322
322
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
324
324
325
325
# Cast bools to uint8 (also one byte)
326
326
if img .dtype == np .bool :
@@ -329,16 +329,21 @@ def imshow(
329
329
if range_color is not None :
330
330
zmin = range_color [0 ]
331
331
zmax = range_color [1 ]
332
+
333
+ # -------- Contrast rescaling: either minmax or infer ------------------
332
334
if contrast_rescaling is None :
333
335
contrast_rescaling = "minmax" if img .ndim == 2 else "infer"
334
336
337
+ # We try to set zmin and zmax only if necessary, because traces have good defaults
335
338
if contrast_rescaling == "minmax" :
339
+ # When using binary_string and minmax we need to set zmin and zmax to rescale the image
336
340
if (zmin is not None or binary_string ) and zmax is None :
337
341
zmax = img .max ()
338
342
if (zmax is not None or binary_string ) and zmin is None :
339
343
zmin = img .min ()
340
344
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 :
342
347
zmax = _infer_zmax_from_type (img )
343
348
if zmin is None and zmax is not None :
344
349
zmin = 0
@@ -395,8 +400,6 @@ def imshow(
395
400
for ch in range (img .shape [- 1 ])
396
401
]
397
402
)
398
- if origin == "lower" :
399
- img_rescaled = img_rescaled [::- 1 ]
400
403
img_str = _array_to_b64str (
401
404
img_rescaled ,
402
405
backend = binary_backend ,
0 commit comments