Skip to content

Commit f79a1c8

Browse files
committed
revert(color): keep the datashader degenerate colorbar at ±0.5 (#700)
Commit 017e0b7 changed _make_continuous_mappable's vmin==vmax fallback from ±0.5 to [0,1] to "unify" it with the pixel norm. That was based on a spurious review finding: _make_continuous_mappable is only the datashader colorbar, and _build_ds_colorbar feeds it the user's explicit norm vmin/vmax — so for an explicit vmin==vmax norm the change shifted the colorbar and broke the 4 *_datashader_norm_vmin_eq_vmax_* baselines. matplotlib pixels and a datashader colorbar never co-occur, so there was no real divergence to fix. Restore the original ±0.5 behavior; drop the parity test.
1 parent d3cce20 commit f79a1c8

2 files changed

Lines changed: 2 additions & 14 deletions

File tree

‎src/spatialdata_plot/pl/_color.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,9 @@ def _is_color_like(color: Any) -> bool:
105105

106106

107107
def _make_continuous_mappable(vmin: float, vmax: float, cmap: Any) -> ScalarMappable:
108-
"""Build a ``ScalarMappable`` for a continuous colorbar.
109-
110-
A degenerate ``vmin == vmax`` falls back to ``[0, 1]`` — the same rule as
111-
:func:`_resolve_continuous_norm`, so the colorbar agrees with the pixel mapping.
112-
"""
108+
"""Build a ``ScalarMappable`` for a continuous colorbar, with a ±0.5 fallback when ``vmin == vmax``."""
113109
if vmin == vmax:
114-
vmin, vmax = 0.0, 1.0
110+
vmin, vmax = vmin - 0.5, vmax + 0.5
115111
return ScalarMappable(norm=Normalize(vmin=vmin, vmax=vmax), cmap=cmap)
116112

117113

‎tests/pl/test_utils.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -888,14 +888,6 @@ def test_degenerate_range_resets_to_unit_interval(self):
888888
norm = _resolve_continuous_norm(np.array([5.0, 5.0, 5.0]), self._params())
889889
assert (norm.vmin, norm.vmax) == (0.0, 1.0)
890890

891-
def test_degenerate_clim_matches_colorbar_mappable(self):
892-
# pixel norm and the (datashader) colorbar mappable must agree on a constant column
893-
from spatialdata_plot.pl._color import _make_continuous_mappable, _resolve_continuous_norm
894-
895-
norm = _resolve_continuous_norm(np.array([5.0, 5.0]), self._params())
896-
mappable = _make_continuous_mappable(5.0, 5.0, self._params().cmap)
897-
assert (norm.vmin, norm.vmax) == (mappable.norm.vmin, mappable.norm.vmax) == (0.0, 1.0)
898-
899891
def test_degenerate_lognorm_is_left_untouched(self):
900892
# LogNorm domain excludes 0, so the degenerate reset must not fire for it
901893
from matplotlib.colors import LogNorm

0 commit comments

Comments
 (0)