diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index c23aa5cf4fd5..4f9f04c324d4 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -222,96 +222,41 @@ def _set_ticks_on_axis_warn(*args, **kw): cbook._warn_external("Use the colorbar set_ticks() method instead.") -class _ColorbarAutoLocator(ticker.MaxNLocator): - """ - AutoLocator for Colorbar - - This locator is just a `.MaxNLocator` except the min and max are - clipped by the norm's min and max (i.e. vmin/vmax from the - image/pcolor/contour object). This is necessary so ticks don't - extrude into the "extend regions". - """ - - def __init__(self, colorbar): - """ - This ticker needs to know the *colorbar* so that it can access - its *vmin* and *vmax*. Otherwise it is the same as - `~.ticker.AutoLocator`. - """ - - self._colorbar = colorbar - nbins = 'auto' - steps = [1, 2, 2.5, 5, 10] - super().__init__(nbins=nbins, steps=steps) - - def tick_values(self, vmin, vmax): - # flip if needed: - if vmin > vmax: - vmin, vmax = vmax, vmin - vmin = max(vmin, self._colorbar.norm.vmin) - vmax = min(vmax, self._colorbar.norm.vmax) - ticks = super().tick_values(vmin, vmax) - rtol = (vmax - vmin) * 1e-10 - return ticks[(ticks >= vmin - rtol) & (ticks <= vmax + rtol)] - - -class _ColorbarAutoMinorLocator(ticker.AutoMinorLocator): - """ - AutoMinorLocator for Colorbar - - This locator is just a `.AutoMinorLocator` except the min and max are - clipped by the norm's min and max (i.e. vmin/vmax from the - image/pcolor/contour object). This is necessary so that the minorticks - don't extrude into the "extend regions". - """ - - def __init__(self, colorbar, n=None): - """ - This ticker needs to know the *colorbar* so that it can access - its *vmin* and *vmax*. - """ +class _LocatorWrapper(): + def __init__(self, parentLocator, colorbar=None): + self.__class__ = type(parentLocator.__class__.__name__, + (self.__class__, parentLocator.__class__), + {}) + self.__dict__ = parentLocator.__dict__ self._colorbar = colorbar - self.ndivs = n - super().__init__(n=None) - def __call__(self): + def _trim_ticks(self, ticks): + if len(ticks) == 0: + return ticks vmin = self._colorbar.norm.vmin vmax = self._colorbar.norm.vmax - ticks = super().__call__() - rtol = (vmax - vmin) * 1e-10 - return ticks[(ticks >= vmin - rtol) & (ticks <= vmax + rtol)] - - -class _ColorbarLogLocator(ticker.LogLocator): - """ - LogLocator for Colorbarbar - - This locator is just a `.LogLocator` except the min and max are - clipped by the norm's min and max (i.e. vmin/vmax from the - image/pcolor/contour object). This is necessary so ticks don't - extrude into the "extend regions". + if hasattr(self._colorbar.norm, '_scale'): + trans = self._colorbar.norm._scale._transform.transform + else: + trans = mtransforms.IdentityTransform().transform + rtol = (trans(vmax) - trans(vmin)) * 1e-10 + good = ((trans(ticks) >= trans(vmin) - rtol) & + (trans(ticks) <= trans(vmax) + rtol)) + return ticks[good] - """ - def __init__(self, colorbar, *args, **kwargs): - """ - This ticker needs to know the *colorbar* so that it can access - its *vmin* and *vmax*. Otherwise it is the same as - `~.ticker.LogLocator`. The ``*args`` and ``**kwargs`` are the - same as `~.ticker.LogLocator`. - """ - self._colorbar = colorbar - super().__init__(*args, **kwargs) + def __call__(self): + ticks = super().__call__() + return self._trim_ticks(np.asarray(ticks)) def tick_values(self, vmin, vmax): - if vmin > vmax: - vmin, vmax = vmax, vmin - vmin = max(vmin, self._colorbar.norm.vmin) - vmax = min(vmax, self._colorbar.norm.vmax) + if vmin is not None and vmax is not None and vmin > vmax: + vmax, vmin = vmin, vmax + if vmin is not None: + vmin = max(vmin, self._colorbar.norm.vmin) + if vmax is not None: + vmax = min(vmax, self._colorbar.norm.vmax) ticks = super().tick_values(vmin, vmax) - rtol = (np.log10(vmax) - np.log10(vmin)) * 1e-10 - ticks = ticks[(np.log10(ticks) >= np.log10(vmin) - rtol) & - (np.log10(ticks) <= np.log10(vmax) + rtol)] - return ticks + return self._trim_ticks(np.asarray(ticks)) class _ColorbarSpine(mspines.Spine): @@ -488,7 +433,9 @@ def __init__(self, ax, cmap=None, self.ax.add_collection(self.dividers) self.locator = None + self.minorlocator = None self.formatter = None + self.minorformatter = None self._manual_tick_data_values = None self.__scale = None # linear, log10 for now. Hopefully more? @@ -510,6 +457,18 @@ def __init__(self, ax, cmap=None, self.formatter = format # Assume it is a Formatter or None self.draw_all() + def _long_axis(self): + if self.orientation == 'vertical': + return self.ax.yaxis + else: + return self.ax.xaxis + + def _short_axis(self): + if self.orientation == 'vertical': + return self.ax.xaxis + else: + return self.ax.yaxis + def _extend_lower(self): """Return whether the lower limit is open ended.""" return self.extend in ('both', 'min') @@ -552,19 +511,16 @@ def config_axis(self): def _config_axis(self): """Set up long and short axis.""" - ax = self.ax if self.orientation == 'vertical': - long_axis, short_axis = ax.yaxis, ax.xaxis if mpl.rcParams['ytick.minor.visible']: self.minorticks_on() else: - long_axis, short_axis = ax.xaxis, ax.yaxis if mpl.rcParams['xtick.minor.visible']: self.minorticks_on() - long_axis.set(label_position=self.ticklocation, - ticks_position=self.ticklocation) - short_axis.set_ticks([]) - short_axis.set_ticks([], minor=True) + self._long_axis().set(label_position=self.ticklocation, + ticks_position=self.ticklocation) + self._short_axis().set_ticks([]) + self._short_axis().set_ticks([], minor=True) self.stale = True def _get_ticker_locator_formatter(self): @@ -577,30 +533,19 @@ def _get_ticker_locator_formatter(self): """ locator = self.locator formatter = self.formatter - if locator is None: - if self.boundaries is None: - if isinstance(self.norm, colors.NoNorm): - nv = len(self._values) - base = 1 + int(nv / 10) - locator = ticker.IndexLocator(base=base, offset=0) - elif isinstance(self.norm, colors.BoundaryNorm): - b = self.norm.boundaries - locator = ticker.FixedLocator(b, nbins=10) - elif isinstance(self.norm, colors.LogNorm): - locator = _ColorbarLogLocator(self) - elif isinstance(self.norm, colors.SymLogNorm): - # The subs setting here should be replaced - # by logic in the locator. - locator = ticker.SymmetricalLogLocator( - subs=np.arange(1, 10), - linthresh=self.norm.linthresh, - base=10) - else: - if mpl.rcParams['_internal.classic_mode']: - locator = ticker.MaxNLocator() - else: - locator = _ColorbarAutoLocator(self) - else: + minorlocator = self.minorlocator + minorformatter = self.minorformatter + + if (self.boundaries is None and + not isinstance(self.norm, colors.BoundaryNorm)): + if locator is None: + locator = _LocatorWrapper( + self._long_axis().get_major_locator(), colorbar=self) + if minorlocator is None: + minorlocator = _LocatorWrapper( + self._long_axis().get_minor_locator(), colorbar=self) + else: + if locator is None: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) @@ -616,9 +561,9 @@ def _get_ticker_locator_formatter(self): formatter = self.formatter self.locator = locator + self.minorlocator = minorlocator self.formatter = formatter - _log.debug('locator: %r', locator) - return locator, formatter + self.minorformatter = minorformatter def _use_auto_colorbar_locator(self): """ @@ -626,8 +571,7 @@ def _use_auto_colorbar_locator(self): one. (check is used twice so factored out here...) """ contouring = self.boundaries is not None and self.spacing == 'uniform' - return (type(self.norm) in [colors.Normalize, colors.LogNorm] and - not contouring) + return (hasattr(self.norm, '_scale') and not contouring) def _reset_locator_formatter_scale(self): """ @@ -636,14 +580,16 @@ def _reset_locator_formatter_scale(self): the mappable normal gets changed: Colorbar.update_normal) """ self.locator = None + self.minorlocator = None self.formatter = None - if isinstance(self.norm, colors.LogNorm): - # *both* axes are made log so that determining the - # mid point is easier. - self.ax.set_xscale('log') - self.ax.set_yscale('log') - self.minorticks_on() - self.__scale = 'log' + if hasattr(self.norm, '_scale'): + self.ax.set_xscale(self.norm._scale.name, + **self.norm._scale._kwargs) + self.ax.set_yscale(self.norm._scale.name, + **self.norm._scale._kwargs) + self.ax.xaxis._scale = self.norm._scale + self.ax.yaxis._scale = self.norm._scale + self.__scale = self.norm._scale.name else: self.ax.set_xscale('linear') self.ax.set_yscale('linear') @@ -659,18 +605,22 @@ def update_ticks(self): """ ax = self.ax # Get the locator and formatter; defaults to self.locator if not None. - locator, formatter = self._get_ticker_locator_formatter() - long_axis = ax.yaxis if self.orientation == 'vertical' else ax.xaxis + self._get_ticker_locator_formatter() if self._use_auto_colorbar_locator(): - _log.debug('Using auto colorbar locator %r on colorbar', locator) - long_axis.set_major_locator(locator) - long_axis.set_major_formatter(formatter) + _log.debug('Using auto colorbar locator %r on colorbar', + self.locator) + self._long_axis().set_major_locator(self.locator) + if self.minorlocator is not None: + self._long_axis().set_minor_locator(self.minorlocator) + self._long_axis().set_major_formatter(self.formatter) else: _log.debug('Using fixed locator on colorbar') - ticks, ticklabels, offset_string = self._ticker(locator, formatter) - long_axis.set_ticks(ticks) - long_axis.set_ticklabels(ticklabels) - long_axis.get_major_formatter().set_offset_string(offset_string) + ticks, ticklabels, offset_string = self._ticker(self.locator, + self.formatter) + self._long_axis().set_ticks(ticks) + self._long_axis().set_ticklabels(ticklabels) + fmt = self._long_axis().get_major_formatter() + fmt.set_offset_string(offset_string) def set_ticks(self, ticks, update_ticks=True): """ @@ -700,10 +650,7 @@ def set_ticks(self, ticks, update_ticks=True): def get_ticks(self, minor=False): """Return the x ticks as a list of locations.""" if self._manual_tick_data_values is None: - ax = self.ax - long_axis = ( - ax.yaxis if self.orientation == 'vertical' else ax.xaxis) - return long_axis.get_majorticklocs() + return self._long_axis().get_majorticklocs() else: # We made the axes manually, the old way, and the ylim is 0-1, # so the majorticklocs are in those units, not data units. @@ -729,21 +676,23 @@ def minorticks_on(self): Turn the minor ticks of the colorbar on without extruding into the "extend regions". """ - ax = self.ax - long_axis = ax.yaxis if self.orientation == 'vertical' else ax.xaxis - if long_axis.get_scale() == 'log': - long_axis.set_minor_locator(_ColorbarLogLocator(self, base=10., - subs='auto')) - long_axis.set_minor_formatter(ticker.LogFormatterSciNotation()) - else: - long_axis.set_minor_locator(_ColorbarAutoMinorLocator(self)) + # get the default from the parent so we don't duplicate logic. + self.ax.minorticks_on() + self._short_axis().set_minor_locator(ticker.NullLocator()) + + # now wrap the default: + loc = _LocatorWrapper(self._long_axis().get_minor_locator(), + colorbar=self) + + self.minorlocator = loc + self._long_axis().set_minor_locator(loc) def minorticks_off(self): """Turn the minor ticks of the colorbar off.""" ax = self.ax - long_axis = ax.yaxis if self.orientation == 'vertical' else ax.xaxis - long_axis.set_minor_locator(ticker.NullLocator()) + self.minorlocator = ticker.NullLocator() + self._long_axis().set_minor_locator(self.minorlocator) def set_label(self, label, *, loc=None, **kwargs): """ @@ -1270,6 +1219,7 @@ def update_bruteforce(self, mappable): # colorbar methods, those changes will be lost. self.ax.cla() self.locator = None + self.minorlocator = None self.formatter = None # clearing the axes will delete outline, patch, solids, and lines: diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 0004d89a3a89..92e0d595c84e 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -1096,6 +1096,7 @@ def __init__(self, vmin=None, vmax=None, clip=False): self.vmin = _sanitize_extrema(vmin) self.vmax = _sanitize_extrema(vmax) self.clip = clip + self._scale = scale.LinearScale(axis=None) @staticmethod def process_value(value): @@ -1250,6 +1251,7 @@ def __init__(self, vcenter, vmin=None, vmax=None): if vcenter is not None and vmin is not None and vcenter <= vmin: raise ValueError('vmin, vcenter, and vmax must be in ' 'ascending order') + self._scale = scale.LinearScale(axis=None) def autoscale_None(self, A): """ @@ -1316,6 +1318,7 @@ def __init__(self, vcenter=0, halfrange=None, clip=False): # calling the halfrange setter to set vmin and vmax self.halfrange = halfrange self.clip = clip + self._scale = scale.LinearScale(axis=None) def _set_vmin_vmax(self): """ diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index e5e9d012f3b0..bdebab5d6ae9 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -53,6 +53,7 @@ def __init__(self, axis): be used: a single scale object should be usable by multiple `~matplotlib.axis.Axis`\es at the same time. """ + self._kwargs = dict() def get_transform(self): """ @@ -92,6 +93,8 @@ def __init__(self, axis): # the docstring of Axis.set_scale. """ """ + self._transform = IdentityTransform() + self._kwargs = dict() def set_default_locators_and_formatters(self, axis): # docstring inherited @@ -110,7 +113,7 @@ def get_transform(self): Return the transform for linear scaling, which is just the `~matplotlib.transforms.IdentityTransform`. """ - return IdentityTransform() + return self._transform class FuncTransform(Transform): @@ -173,6 +176,7 @@ def forward(values: array-like) -> array-like forward, inverse = functions transform = FuncTransform(forward, inverse) self._transform = transform + self._kwargs = {'functions': functions} def get_transform(self): """Return the `.FuncTransform` associated with this scale.""" @@ -296,6 +300,7 @@ def __init__(*, base=10, subs=None, nonpositive="clip"): base, subs, nonpositive = __init__(**kwargs) self._transform = LogTransform(base, nonpositive) self.subs = subs + self._kwargs = kwargs base = property(lambda self: self._transform.base) @@ -349,6 +354,7 @@ def forward(values: array-like) -> array-like forward, inverse = functions self.subs = None self._transform = FuncTransform(forward, inverse) + LogTransform(base) + self._kwargs = {'functions': functions, 'base': base} @property def base(self): @@ -476,6 +482,7 @@ def __init__(*, base=10, linthresh=2, subs=None, linscale=1): base, linthresh, subs, linscale = __init__(**kwargs) self._transform = SymmetricalLogTransform(base, linthresh, linscale) self.subs = subs + self._kwargs = kwargs base = property(lambda self: self._transform.base) linthresh = property(lambda self: self._transform.linthresh) @@ -569,6 +576,8 @@ def __init__(self, axis, nonpositive='mask', *, self._transform = LogitTransform(nonpositive) self._use_overline = use_overline self._one_half = one_half + self._kwargs = {'nonpositive': nonpositive, 'one_half': one_half, + 'use_overline': use_overline} def get_transform(self): """Return the `.LogitTransform` associated with this scale.""" diff --git a/lib/matplotlib/tests/baseline_images/test_colorbar/colorbar_single_scatter.png b/lib/matplotlib/tests/baseline_images/test_colorbar/colorbar_single_scatter.png index 63a58245f7e0..cce7fcd8e029 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_colorbar/colorbar_single_scatter.png and b/lib/matplotlib/tests/baseline_images/test_colorbar/colorbar_single_scatter.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout11.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout11.png index 514bf02ce13c..ad11fe7ec370 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout11.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout11.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout11rat.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout11rat.png index b674803ba2e8..1b6fca0e4653 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout11rat.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout11rat.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout13.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout13.png index 5889b0583432..f7b0e3e3647d 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout13.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout13.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout14.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout14.png index e030c3c9f6c1..772213d6e895 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout14.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout14.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout3.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout3.png index c679609be54e..4ea2fc7968ff 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout3.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout3.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout4.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout4.png index 2a6e55c08f64..6498f95983bf 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout4.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout4.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout5.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout5.png index af691c44867d..e9c02567d190 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout5.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout5.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout6.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout6.png index 6ba96e41a34d..a07d3c8a36de 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout6.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout6.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout8.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout8.png index 757230e25363..874ebbf837e3 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout8.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout8.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout9.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout9.png index 59fd2c76c5bc..64296b855637 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout9.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout9.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/test_colorbar_location.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/test_colorbar_location.png index 2ca5a5c29eb1..c8a8eaf94552 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/test_colorbar_location.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/test_colorbar_location.png differ diff --git a/lib/matplotlib/tests/test_colorbar.py b/lib/matplotlib/tests/test_colorbar.py index bbd1e9c5f590..1ca8b90ef4a7 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -9,7 +9,7 @@ import matplotlib.pyplot as plt from matplotlib.colors import (BoundaryNorm, LogNorm, PowerNorm, Normalize, TwoSlopeNorm) -from matplotlib.colorbar import ColorbarBase, _ColorbarLogLocator +from matplotlib.colorbar import ColorbarBase from matplotlib.ticker import FixedLocator @@ -482,14 +482,13 @@ def test_colorbar_renorm(): im = ax.imshow(z) cbar = fig.colorbar(im) np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(), - np.arange(0, 120000.1, 15000)) + np.arange(0, 120000.1, 20000)) cbar.set_ticks([1, 2, 3]) assert isinstance(cbar.locator, FixedLocator) norm = LogNorm(z.min(), z.max()) im.set_norm(norm) - assert isinstance(cbar.locator, _ColorbarLogLocator) np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(), np.logspace(-8, 5, 14)) # note that set_norm removes the FixedLocator... @@ -514,13 +513,13 @@ def test_colorbar_format(): im = ax.imshow(z) cbar = fig.colorbar(im, format='%4.2e') fig.canvas.draw() - assert cbar.ax.yaxis.get_ticklabels()[4].get_text() == '6.00e+04' + assert cbar.ax.yaxis.get_ticklabels()[4].get_text() == '8.00e+04' # make sure that if we change the clim of the mappable that the # formatting is *not* lost: im.set_clim([4, 200]) fig.canvas.draw() - assert cbar.ax.yaxis.get_ticklabels()[4].get_text() == '8.00e+01' + assert cbar.ax.yaxis.get_ticklabels()[2].get_text() == '1.50e+02' # but if we change the norm: im.set_norm(LogNorm(vmin=0.1, vmax=10)) diff --git a/lib/matplotlib/tests/test_constrainedlayout.py b/lib/matplotlib/tests/test_constrainedlayout.py index 7ea92a160c11..d2c62019ab30 100644 --- a/lib/matplotlib/tests/test_constrainedlayout.py +++ b/lib/matplotlib/tests/test_constrainedlayout.py @@ -51,8 +51,6 @@ def test_constrained_layout2(): @image_comparison(['constrained_layout3.png']) def test_constrained_layout3(): """Test constrained_layout for colorbars with subplots""" - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False fig, axs = plt.subplots(2, 2, constrained_layout=True) for nn, ax in enumerate(axs.flat): @@ -67,8 +65,6 @@ def test_constrained_layout3(): @image_comparison(['constrained_layout4.png']) def test_constrained_layout4(): """Test constrained_layout for a single colorbar with subplots""" - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False fig, axs = plt.subplots(2, 2, constrained_layout=True) for ax in axs.flat: @@ -82,8 +78,6 @@ def test_constrained_layout5(): Test constrained_layout for a single colorbar with subplots, colorbar bottom """ - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False fig, axs = plt.subplots(2, 2, constrained_layout=True) for ax in axs.flat: @@ -96,8 +90,6 @@ def test_constrained_layout5(): @image_comparison(['constrained_layout6.png'], tol=0.002) def test_constrained_layout6(): """Test constrained_layout for nested gridspecs""" - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False fig = plt.figure(constrained_layout=True) gs = fig.add_gridspec(1, 2, figure=fig) @@ -139,8 +131,6 @@ def test_constrained_layout7(): @image_comparison(['constrained_layout8.png']) def test_constrained_layout8(): """Test for gridspecs that are not completely full""" - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False fig = plt.figure(figsize=(10, 5), constrained_layout=True) gs = gridspec.GridSpec(3, 5, figure=fig) @@ -169,8 +159,6 @@ def test_constrained_layout8(): @image_comparison(['constrained_layout9.png']) def test_constrained_layout9(): """Test for handling suptitle and for sharex and sharey""" - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False fig, axs = plt.subplots(2, 2, constrained_layout=True, sharex=False, sharey=False) @@ -195,8 +183,6 @@ def test_constrained_layout10(): @image_comparison(['constrained_layout11.png']) def test_constrained_layout11(): """Test for multiple nested gridspecs""" - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False fig = plt.figure(constrained_layout=True, figsize=(13, 3)) gs0 = gridspec.GridSpec(1, 2, figure=fig) @@ -217,8 +203,6 @@ def test_constrained_layout11(): @image_comparison(['constrained_layout11rat.png']) def test_constrained_layout11rat(): """Test for multiple nested gridspecs with width_ratios""" - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False fig = plt.figure(constrained_layout=True, figsize=(10, 3)) gs0 = gridspec.GridSpec(1, 2, figure=fig, width_ratios=[6, 1]) @@ -261,8 +245,6 @@ def test_constrained_layout12(): @image_comparison(['constrained_layout13.png'], tol=2.e-2) def test_constrained_layout13(): """Test that padding works.""" - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False fig, axs = plt.subplots(2, 2, constrained_layout=True) for ax in axs.flat: @@ -274,8 +256,6 @@ def test_constrained_layout13(): @image_comparison(['constrained_layout14.png']) def test_constrained_layout14(): """Test that padding works.""" - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False fig, axs = plt.subplots(2, 2, constrained_layout=True) for ax in axs.flat: @@ -402,9 +382,6 @@ def test_colorbar_location(): Test that colorbar handling is as expected for various complicated cases... """ - # Remove this line when this test image is regenerated. - plt.rcParams['pcolormesh.snap'] = False - fig, axs = plt.subplots(4, 5, constrained_layout=True) for ax in axs.flat: pcm = example_pcolor(ax) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 21097e282c73..54ae444bb1d3 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2162,8 +2162,7 @@ def set_params(self, **kwargs): self._nbins = kwargs.pop('nbins') if self._nbins != 'auto': self._nbins = int(self._nbins) - if 'symmetric' in kwargs: - self._symmetric = kwargs.pop('symmetric') + self._symmetric = kwargs.pop('symmetric', False) if 'prune' in kwargs: prune = kwargs.pop('prune') _api.check_in_list(['upper', 'lower', 'both', None], prune=prune) diff --git a/lib/mpl_toolkits/tests/test_axes_grid.py b/lib/mpl_toolkits/tests/test_axes_grid.py index 2c2a9e785a96..fbebb1f8cb87 100644 --- a/lib/mpl_toolkits/tests/test_axes_grid.py +++ b/lib/mpl_toolkits/tests/test_axes_grid.py @@ -63,4 +63,3 @@ def test_imagegrid(): ax = grid[0] im = ax.imshow([[1, 2]], norm=mpl.colors.LogNorm()) cb = ax.cax.colorbar(im) - assert isinstance(cb.locator, mpl.colorbar._ColorbarLogLocator)