From 267f1ea368262964e5e2d978a2d5e029988a8ebe Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 8 Jul 2020 17:51:37 -0400 Subject: [PATCH] API: resolve unset vmin / vmax in all ScalarMapple based methods closes #17703 --- .../api_changes_3.3.0/behaviour.rst | 33 +++++++++++++++++-- lib/matplotlib/cm.py | 6 ++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/doc/api/prev_api_changes/api_changes_3.3.0/behaviour.rst b/doc/api/prev_api_changes/api_changes_3.3.0/behaviour.rst index 40b1bb3d79d8..2b21794ede6b 100644 --- a/doc/api/prev_api_changes/api_changes_3.3.0/behaviour.rst +++ b/doc/api/prev_api_changes/api_changes_3.3.0/behaviour.rst @@ -96,9 +96,10 @@ internal quotes) now cause a ValueError to be raised. `.SymLogNorm` now has a *base* parameter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Previously, `.SymLogNorm` had no *base* kwarg, and defaulted to ``base=np.e`` -whereas the documentation said it was ``base=10``. In preparation to make -the default 10, calling `.SymLogNorm` without the new *base* kwarg emits a +Previously, `.SymLogNorm` had no *base* keyword argument, and +defaulted to ``base=np.e`` whereas the documentation said it was +``base=10``. In preparation to make the default 10, calling +`.SymLogNorm` without the new *base* keyword argument emits a deprecation warning. @@ -312,3 +313,29 @@ rcParam is True. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The *colors* parameter will now default to :rc:`lines.color`, while previously it defaulted to 'k'. + +Aggressively autoscale clim in ``ScalerMappable`` classes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +Previously some plotting methods would defer autoscaling until the +first draw if only one of the *vmin* or *vmax* keyword arguments were +passed (`.Axes.scatter`, `.Axes.hexbin`, `.Axes.imshow`, +`.Axes.pcolorfast`) but would scale based on the passed data if +neither was passed (independent of the *norm* keyword arguments). +Other methods (`.Axes.pcolor`, `.Axes.pcolormesh`) always autoscaled +base on the initial data. + +All of the plotting methods now resolve the unset *vmin* or *vmax* +at the initial call time using the data passed in. + +If you were relying on exactly one of the *vmin* or *vmax* remaining +unset between the time when the method is called and the first time +the figure is rendered you get back the old behavior by manually setting +the relevant limit back to `None` :: + + cm_obj.norm.vmin = None + # or + cm_obj.norm.vmax = None + +which will be resolved during the draw process. diff --git a/lib/matplotlib/cm.py b/lib/matplotlib/cm.py index 141bbdbb9dbf..f7b5d5b3465a 100644 --- a/lib/matplotlib/cm.py +++ b/lib/matplotlib/cm.py @@ -258,8 +258,10 @@ def _scale_norm(self, norm, vmin, vmax): "simultaneously is deprecated since %(since)s and " "will become an error %(removal)s. Please pass " "vmin/vmax directly to the norm when creating it.") - else: - self.autoscale_None() + + # always resolve the autoscaling so we have concrete limits + # rather than deferring to draw time. + self.autoscale_None() def to_rgba(self, x, alpha=None, bytes=False, norm=True): """