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

Skip to content

Added check in autoscale_None for completely masked pcolor plots. #2336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2013
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
10 changes: 5 additions & 5 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,10 @@ def __call__(self, value, clip=None):

self.autoscale_None(result)
vmin, vmax = self.vmin, self.vmax
if vmin > vmax:
raise ValueError("minvalue must be less than or equal to maxvalue")
elif vmin == vmax:
if vmin == vmax:
result.fill(0) # Or should it be all masked? Or 0.5?
elif vmin > vmax:
raise ValueError("minvalue must be less than or equal to maxvalue")
else:
vmin = float(vmin)
vmax = float(vmax)
Expand Down Expand Up @@ -920,9 +920,9 @@ def autoscale(self, A):

def autoscale_None(self, A):
' autoscale only None-valued vmin or vmax'
if self.vmin is None:
if self.vmin is None and np.size(A) > 0:
self.vmin = ma.min(A)
if self.vmax is None:
if self.vmax is None and np.size(A) > 0:
self.vmax = ma.max(A)

def scaled(self):
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from numpy.testing.utils import assert_array_equal
import matplotlib.colors as mcolors
import matplotlib.cm as cm
import matplotlib.pyplot as plt
from matplotlib.testing.decorators import cleanup


def test_colormap_endian():
"""
Expand All @@ -23,6 +26,7 @@ def test_colormap_endian():
#print(anative.dtype.isnative, aforeign.dtype.isnative)
assert_array_equal(cmap(anative), cmap(aforeign))


def test_BoundaryNorm():
"""
Github issue #1258: interpolation was failing with numpy
Expand All @@ -36,6 +40,7 @@ def test_BoundaryNorm():
ncolors = len(boundaries)
bn = mcolors.BoundaryNorm(boundaries, ncolors)
assert_array_equal(bn(vals), expected)


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


@cleanup
def test_autoscale_masked():
# Test for #2336. Previously fully masked data would trigger a ValueError.
data = np.ma.masked_all((12, 20))
plt.pcolor(data)
plt.draw()