From 0e24001c95fc2215efd212ce09e84c1604ed8d1e Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sun, 2 Feb 2020 20:32:10 -0800 Subject: [PATCH] FIX: properly fallback bad scale --- lib/matplotlib/colorbar.py | 18 ++++++++++++------ lib/matplotlib/tests/test_colorbar.py | 1 - 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 72f30723ae64..b23ac8f7dc52 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -452,6 +452,7 @@ def __init__(self, ax, cmap=None, self.locator = None self.formatter = None self._manual_tick_data_values = None + self.__scale = None # linear, log10 for now. Hopefully more? if ticklocation == 'auto': ticklocation = 'bottom' if orientation == 'horizontal' else 'right' @@ -585,8 +586,8 @@ 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 (type(self.norm) in [colors.Normalize, colors.LogNorm] and + not contouring) def _reset_locator_formatter_scale(self): """ @@ -602,9 +603,14 @@ def _reset_locator_formatter_scale(self): self.ax.set_xscale('log') self.ax.set_yscale('log') self.minorticks_on() + self.__scale = 'log' else: self.ax.set_xscale('linear') self.ax.set_yscale('linear') + if type(self.norm) is colors.Normalize: + self.__scale = 'linear' + else: + self.__scale = 'manual' def update_ticks(self): """ @@ -1119,13 +1125,13 @@ def _mesh(self): else: y = self._proportional_y() xmid = np.array([0.5]) - try: + if self.__scale != 'manual': y = norm.inverse(y) x = norm.inverse(x) xmid = norm.inverse(xmid) - except ValueError: - # occurs for norms that don't have an inverse, in - # which case manually scale: + else: + # if a norm doesn't have a named scale, or + # we are not using a norm dv = self.vmax - self.vmin x = x * dv + self.vmin y = y * dv + self.vmin diff --git a/lib/matplotlib/tests/test_colorbar.py b/lib/matplotlib/tests/test_colorbar.py index 3932177565c5..eaee1b4d727d 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -373,7 +373,6 @@ def test_colorbar_get_ticks(): data = np.arange(1200).reshape(30, 40) levels = [0, 200, 400, 600, 800, 1000, 1200] - plt.subplot() plt.contourf(data, levels=levels) # testing getter for user set ticks pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy