From c4867bd6770203fc09492b4fe3bf23891b412291 Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Mon, 10 Feb 2020 10:35:01 -1000 Subject: [PATCH] Backport PR #16392: FIX colorbars for Norms that do not have a scale. --- lib/matplotlib/colorbar.py | 22 +++++++++++++--------- lib/matplotlib/tests/test_colorbar.py | 1 - 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 301461af8c25..92926ee6a870 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -485,6 +485,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' @@ -611,11 +612,9 @@ def _use_auto_colorbar_locator(self): Return if we should use an adjustable tick locator or a fixed one. (check is used twice so factored out here...) """ - contouring = ((self.boundaries is not None) and - (self.spacing == 'uniform')) - return (((type(self.norm) == colors.Normalize) - or (type(self.norm) == colors.LogNorm)) - and not contouring) + contouring = self.boundaries is not None and self.spacing == 'uniform' + return (type(self.norm) in [colors.Normalize, colors.LogNorm] and + not contouring) def _reset_locator_formatter_scale(self): """ @@ -631,9 +630,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): """ @@ -1123,13 +1127,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 27eaeb159a76..6d1f39149e09 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -375,7 +375,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