diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index a5546309929b..9277d2b12fbe 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -961,15 +961,17 @@ def autoscale(self, A): """ Set *vmin*, *vmax* to min, max of *A*. """ - self.vmin = np.ma.min(A) - self.vmax = np.ma.max(A) + A = np.asanyarray(A) + self.vmin = A.min() + self.vmax = A.max() def autoscale_None(self, A): - ' autoscale only None-valued vmin or vmax' - if self.vmin is None and np.size(A) > 0: - self.vmin = np.ma.min(A) - if self.vmax is None and np.size(A) > 0: - self.vmax = np.ma.max(A) + """autoscale only None-valued vmin or vmax.""" + A = np.asanyarray(A) + if self.vmin is None and A.size: + self.vmin = A.min() + if self.vmax is None and A.size: + self.vmax = A.max() def scaled(self): 'return true if vmin and vmax set' @@ -1037,14 +1039,14 @@ def autoscale(self, A): self.vmax = np.ma.max(A) def autoscale_None(self, A): - ' autoscale only None-valued vmin or vmax' + """autoscale only None-valued vmin or vmax.""" if self.vmin is not None and self.vmax is not None: return A = np.ma.masked_less_equal(A, 0, copy=False) - if self.vmin is None: - self.vmin = np.ma.min(A) - if self.vmax is None: - self.vmax = np.ma.max(A) + if self.vmin is None and A.size: + self.vmin = A.min() + if self.vmax is None and A.size: + self.vmax = A.max() class SymLogNorm(Normalize): @@ -1153,13 +1155,14 @@ def autoscale(self, A): self._transform_vmin_vmax() def autoscale_None(self, A): - """ autoscale only None-valued vmin or vmax """ + """autoscale only None-valued vmin or vmax.""" if self.vmin is not None and self.vmax is not None: pass - if self.vmin is None: - self.vmin = np.ma.min(A) - if self.vmax is None: - self.vmax = np.ma.max(A) + A = np.asanyarray(A) + if self.vmin is None and A.size: + self.vmin = A.min() + if self.vmax is None and A.size: + self.vmax = A.max() self._transform_vmin_vmax() @@ -1223,20 +1226,19 @@ def autoscale(self, A): self.vmin = 0 warnings.warn("Power-law scaling on negative values is " "ill-defined, clamping to 0.") - self.vmax = np.ma.max(A) def autoscale_None(self, A): - ' autoscale only None-valued vmin or vmax' - if self.vmin is None and np.size(A) > 0: - self.vmin = np.ma.min(A) + """autoscale only None-valued vmin or vmax.""" + A = np.asanyarray(A) + if self.vmin is None and A.size: + self.vmin = A.min() if self.vmin < 0: self.vmin = 0 warnings.warn("Power-law scaling on negative values is " "ill-defined, clamping to 0.") - - if self.vmax is None and np.size(A) > 0: - self.vmax = np.ma.max(A) + if self.vmax is None and A.size: + self.vmax = A.max() class BoundaryNorm(Normalize): diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 69c2f1f27b18..ba4e2dd80f99 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -2,29 +2,26 @@ unicode_literals) import six + +from copy import copy import io import os import warnings import numpy as np +from numpy import ma from numpy.testing import assert_array_equal -from matplotlib.testing.decorators import image_comparison +from matplotlib import ( + colors, image as mimage, mlab, patches, pyplot as plt, + rc_context, rcParams) from matplotlib.image import (AxesImage, BboxImage, FigureImage, NonUniformImage, PcolorImage) +from matplotlib.testing.decorators import image_comparison from matplotlib.transforms import Bbox, Affine2D, TransformedBbox -from matplotlib import rcParams, rc_context -from matplotlib import patches -import matplotlib.pyplot as plt -from matplotlib import mlab import pytest -from copy import copy -from numpy import ma -import matplotlib.image as mimage -import matplotlib.colors as colors - try: from PIL import Image @@ -789,9 +786,16 @@ def test_imshow_flatfield(): im.set_clim(.5, 1.5) -def test_empty_imshow(): +@pytest.mark.parametrize( + "make_norm", + [colors.Normalize, + colors.LogNorm, + lambda: colors.SymLogNorm(1), + lambda: colors.PowerNorm(1)]) +@pytest.mark.filterwarnings("ignore:Attempting to set identical left==right") +def test_empty_imshow(make_norm): fig, ax = plt.subplots() - im = ax.imshow([[]]) + im = ax.imshow([[]], norm=make_norm()) im.set_extent([-5, 5, -5, 5]) fig.canvas.draw()