Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4ec9d5

Browse files
committed
Merge remote-tracking branch 'upstream/v1.2.x' into v1.3.x
Conflicts: lib/matplotlib/tests/test_colors.py
2 parents d3e49b6 + 49b73e7 commit e4ec9d5

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/matplotlib/colors.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,10 @@ def __call__(self, value, clip=None):
901901

902902
self.autoscale_None(result)
903903
vmin, vmax = self.vmin, self.vmax
904-
if vmin > vmax:
905-
raise ValueError("minvalue must be less than or equal to maxvalue")
906-
elif vmin == vmax:
904+
if vmin == vmax:
907905
result.fill(0) # Or should it be all masked? Or 0.5?
906+
elif vmin > vmax:
907+
raise ValueError("minvalue must be less than or equal to maxvalue")
908908
else:
909909
vmin = float(vmin)
910910
vmax = float(vmax)
@@ -942,9 +942,9 @@ def autoscale(self, A):
942942

943943
def autoscale_None(self, A):
944944
' autoscale only None-valued vmin or vmax'
945-
if self.vmin is None:
945+
if self.vmin is None and np.size(A) > 0:
946946
self.vmin = ma.min(A)
947-
if self.vmax is None:
947+
if self.vmax is None and np.size(A) > 0:
948948
self.vmax = ma.max(A)
949949

950950
def scaled(self):

lib/matplotlib/tests/test_colors.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import matplotlib.colors as mcolors
88
import matplotlib.cm as cm
99
import matplotlib.pyplot as plt
10-
from matplotlib.testing.decorators import image_comparison
10+
from matplotlib.testing.decorators import image_comparison, cleanup
1111

1212

1313
def test_colormap_endian():
@@ -175,6 +175,14 @@ def test_cmap_and_norm_from_levels_and_colors2():
175175
assert_raises(ValueError, mcolors.from_levels_and_colors, levels, colors)
176176

177177

178+
@cleanup
179+
def test_autoscale_masked():
180+
# Test for #2336. Previously fully masked data would trigger a ValueError.
181+
data = np.ma.masked_all((12, 20))
182+
plt.pcolor(data)
183+
plt.draw()
184+
185+
178186
if __name__ == '__main__':
179187
import nose
180188
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)