Skip to content

Commit

Permalink
Small cleanups to colorbar.
Browse files Browse the repository at this point in the history
- `__scale = "manual"` doesn't exist anymore since d1c5a6a.
- Shorten Boundary/NoNorm inversion and norm._scale check.
- No need to define `x` well before its use point, and no need to make
  it an array explicitly.
  • Loading branch information
anntzer authored and QuLogic committed Dec 10, 2021
1 parent a7e05bd commit 68e9b15
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/matplotlib/colorbar.py
Expand Up @@ -1132,18 +1132,14 @@ def _mesh(self):
norm = copy.deepcopy(self.norm)
norm.vmin = self.vmin
norm.vmax = self.vmax
x = np.array([0.0, 1.0])
y, extendlen = self._proportional_y()
# invert:
if (isinstance(norm, (colors.BoundaryNorm, colors.NoNorm)) or
(self.__scale == 'manual')):
# if a norm doesn't have a named scale, or we are not using a norm:
dv = self.vmax - self.vmin
y = y * dv + self.vmin
if isinstance(norm, (colors.BoundaryNorm, colors.NoNorm)):
y = y * (self.vmax - self.vmin) + self.vmin # not using a norm.
else:
y = norm.inverse(y)
self._y = y
X, Y = np.meshgrid(x, y)
X, Y = np.meshgrid([0., 1.], y)
if self.orientation == 'vertical':
return (X, Y, extendlen)
else:
Expand Down Expand Up @@ -1183,8 +1179,8 @@ def _reset_locator_formatter_scale(self):
self._set_scale('function', functions=funcs)
elif self.spacing == 'proportional':
self._set_scale('linear')
elif hasattr(self.norm, '_scale') and self.norm._scale is not None:
# use the norm's scale:
elif getattr(self.norm, '_scale', None):
# use the norm's scale (if it exists and is not None):
self._set_scale(self.norm._scale)
elif type(self.norm) is colors.Normalize:
# plain Normalize:
Expand Down

0 comments on commit 68e9b15

Please sign in to comment.