Skip to content

Commit 49b73e7

Browse files
committed
Merge pull request #2336 from pelson/completely_masked
Added check in autoscale_None for completely masked pcolor plots.
2 parents bce389f + 8567877 commit 49b73e7

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lib/matplotlib/colors.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,10 @@ def __call__(self, value, clip=None):
880880

881881
self.autoscale_None(result)
882882
vmin, vmax = self.vmin, self.vmax
883-
if vmin > vmax:
884-
raise ValueError("minvalue must be less than or equal to maxvalue")
885-
elif vmin == vmax:
883+
if vmin == vmax:
886884
result.fill(0) # Or should it be all masked? Or 0.5?
885+
elif vmin > vmax:
886+
raise ValueError("minvalue must be less than or equal to maxvalue")
887887
else:
888888
vmin = float(vmin)
889889
vmax = float(vmax)
@@ -921,9 +921,9 @@ def autoscale(self, A):
921921

922922
def autoscale_None(self, A):
923923
' autoscale only None-valued vmin or vmax'
924-
if self.vmin is None:
924+
if self.vmin is None and np.size(A) > 0:
925925
self.vmin = ma.min(A)
926-
if self.vmax is None:
926+
if self.vmax is None and np.size(A) > 0:
927927
self.vmax = ma.max(A)
928928

929929
def scaled(self):

lib/matplotlib/tests/test_colors.py

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from numpy.testing.utils import assert_array_equal
88
import matplotlib.colors as mcolors
99
import matplotlib.cm as cm
10+
import matplotlib.pyplot as plt
11+
from matplotlib.testing.decorators import cleanup
12+
1013

1114
def test_colormap_endian():
1215
"""
@@ -23,6 +26,7 @@ def test_colormap_endian():
2326
#print(anative.dtype.isnative, aforeign.dtype.isnative)
2427
assert_array_equal(cmap(anative), cmap(aforeign))
2528

29+
2630
def test_BoundaryNorm():
2731
"""
2832
Github issue #1258: interpolation was failing with numpy
@@ -36,6 +40,7 @@ def test_BoundaryNorm():
3640
ncolors = len(boundaries)
3741
bn = mcolors.BoundaryNorm(boundaries, ncolors)
3842
assert_array_equal(bn(vals), expected)
43+
3944

4045
def test_LogNorm():
4146
"""
@@ -46,3 +51,10 @@ def test_LogNorm():
4651
ln = mcolors.LogNorm(clip=True, vmax=5)
4752
assert_array_equal(ln([1, 6]), [0, 1.0])
4853

54+
55+
@cleanup
56+
def test_autoscale_masked():
57+
# Test for #2336. Previously fully masked data would trigger a ValueError.
58+
data = np.ma.masked_all((12, 20))
59+
plt.pcolor(data)
60+
plt.draw()

0 commit comments

Comments
 (0)