Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2945,13 +2945,14 @@ def __call__(self, value, clip=None):
self.autoscale_None(value)
if self.vmin > self.vmax:
raise ValueError("vmin must be less or equal to vmax")
if self.vmin == self.vmax:
return np.full_like(value, 0)
if clip is None:
clip = self.clip
if clip:
value = np.clip(value, self.vmin, self.vmax)
t_value = self._trf.transform(value).reshape(np.shape(value))
if self.vmin == self.vmax:
t_value.fill(0)
return t_value
t_vmin, t_vmax = self._trf.transform([self.vmin, self.vmax])
if not np.isfinite([t_vmin, t_vmax]).all():
raise ValueError("Invalid vmin or vmax")
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,21 @@ def test_LogNorm_inverse():
assert_array_almost_equal([0.4], norm.inverse([0.30103]))


def test_LogNorm_single_valid_value():
"""
Test that non-positive values map to masked result when vmin and vmax are equal.
"""
norm = mcolors.LogNorm()
result = norm([0, 1])

# vmin and vmax are autoscaled to 1, since that is the only valid value.
assert norm.vmin == 1
assert norm.vmax == 1

np.testing.assert_array_equal(result.mask, [True, False])
assert result[1] == 0


def test_PowerNorm():
# Check an exponent of 1 gives same results as a normal linear
# normalization. Also implicitly checks that vmin/vmax are
Expand Down
Loading