Skip to content

Commit 027cce1

Browse files
committed
Added check in autoscale_None for completely masked pcolor plots.
1 parent 85b020c commit 027cce1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/matplotlib/colors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,9 @@ def autoscale(self, A):
920920

921921
def autoscale_None(self, A):
922922
' autoscale only None-valued vmin or vmax'
923-
if self.vmin is None:
923+
if self.vmin is None and np.size(A) > 0:
924924
self.vmin = ma.min(A)
925-
if self.vmax is None:
925+
if self.vmax is None and np.size(A) > 0:
926926
self.vmax = ma.max(A)
927927

928928
def scaled(self):

lib/matplotlib/tests/test_colors.py

Lines changed: 12 additions & 0 deletions
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)