Skip to content

Commit febdfaf

Browse files
committed
range_color case
1 parent 34cc0de commit febdfaf

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,12 @@ def imshow(
287287
if img.dtype == np.bool:
288288
img = 255 * img.astype(np.uint8)
289289

290+
if range_color is not None:
291+
zmin = range_color[0]
292+
zmax = range_color[1]
290293
if contrast_rescaling is None:
291294
contrast_rescaling = "image" if img.ndim == 2 else "dtype"
295+
292296
if contrast_rescaling == "image":
293297
if (zmin is not None or use_binary_string) and zmax is None:
294298
zmax = img.max()
@@ -319,14 +323,13 @@ def imshow(
319323
layout["xaxis"] = dict(scaleanchor="y", constrain="domain")
320324
layout["yaxis"]["constrain"] = "domain"
321325
colorscale_validator = ColorscaleValidator("colorscale", "imshow")
322-
range_color = range_color or [zmin, zmax]
323326
layout["coloraxis1"] = dict(
324327
colorscale=colorscale_validator.validate_coerce(
325328
args["color_continuous_scale"]
326329
),
327330
cmid=color_continuous_midpoint,
328-
cmin=range_color[0],
329-
cmax=range_color[1],
331+
cmin=zmin,
332+
cmax=zmax,
330333
)
331334
if labels["color"]:
332335
layout["coloraxis1"]["colorbar"] = dict(title_text=labels["color"])

packages/python/plotly/plotly/tests/test_core/test_px/test_imshow.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ def test_zmin_zmax_range_color():
141141
assert fig.layout.coloraxis.cmax == 0.8
142142

143143

144+
def test_zmin_zmax_range_color_source():
145+
img = img_gray / 100.0
146+
fig1 = px.imshow(img, zmin=0.2, zmax=0.8, use_binary_string=True)
147+
fig2 = px.imshow(img, range_color=[0.2, 0.8], use_binary_string=True)
148+
assert fig1 == fig2
149+
150+
144151
def test_imshow_xarray():
145152
img = np.random.random((20, 30))
146153
da = xr.DataArray(img, dims=["dim_rows", "dim_cols"])

0 commit comments

Comments
 (0)