diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index cfb19bf95001..5416d58932fc 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -27,6 +27,7 @@ import matplotlib.patches as mpatches import matplotlib.texmanager as texmanager import matplotlib.transforms as mtrans +from matplotlib.cbook import mplDeprecation # Import needed for adding manual selection capability to clabel from matplotlib.blocking_input import BlockingContourLabeler @@ -1198,6 +1199,20 @@ def _contour_level_args(self, z, args): else: raise ValueError("Contour levels must be increasing") + @property + def vmin(self): + warnings.warn("vmin is deprecated and will be removed in 2.2 " + "and not replaced.", + mplDeprecation) + return getattr(self, '_vmin', None) + + @property + def vmax(self): + warnings.warn("vmax is deprecated and will be removed in 2.2 " + "and not replaced.", + mplDeprecation) + return getattr(self, '_vmax', None) + def _process_levels(self): """ Assign values to :attr:`layers` based on :attr:`levels`, @@ -1207,10 +1222,9 @@ def _process_levels(self): a line is a thin layer. No extended levels are needed with line contours. """ - # The following attributes are no longer needed, and - # should be deprecated and removed to reduce confusion. - self.vmin = np.amin(self.levels) - self.vmax = np.amax(self.levels) + # following are deprecated and will be removed in 2.2 + self._vmin = np.amin(self.levels) + self._vmax = np.amax(self.levels) # Make a private _levels to include extended regions; we # want to leave the original levels attribute unchanged. diff --git a/lib/matplotlib/tests/test_contour.py b/lib/matplotlib/tests/test_contour.py index d9af79353d64..2c4383495500 100644 --- a/lib/matplotlib/tests/test_contour.py +++ b/lib/matplotlib/tests/test_contour.py @@ -279,6 +279,25 @@ def test_contourf_decreasing_levels(): assert_equal(len(w), 2) +@cleanup +def test_vminvmax_warning(): + z = [[0.1, 0.3], [0.5, 0.7]] + plt.figure() + cs = plt.contourf(z, [0.0, 1.0]) + + with warnings.catch_warnings(record=True) as w: + cs.vmin + assert len(w) == 1 + assert (str(w[0].message).startswith( + ("vmin is deprecated and will be removed in 2.2 "))) + + with warnings.catch_warnings(record=True) as w: + cs.vmax + assert len(w) == 1 + assert (str(w[0].message).startswith( + ("vmax is deprecated and will be removed in 2.2 "))) + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False)