8000 ENH: make contour colorbars the same as other colorbars · matplotlib/matplotlib@963bc27 · GitHub
[go: up one dir, main page]

Skip to content

Commit 963bc27

Browse files
committed
ENH: make contour colorbars the same as other colorbars
1 parent 74640bb commit 963bc27

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

lib/matplotlib/colorbar.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
is a thin wrapper over :meth:`~matplotlib.figure.Figure.colorbar`.
1919
2020
'''
21-
21+
import copy
2222
import logging
2323

2424
import numpy as np
@@ -484,6 +484,7 @@ def draw_all(self):
484484
# units:
485485
X, Y = self._mesh()
486486
C = self._values[:, np.newaxis]
487+
# decide minor/major axis
487488
self.config_axis()
488489
self._config_axes(X, Y)
489490
if self.filled:
@@ -560,10 +561,8 @@ def _use_auto_colorbar_locator(self):
560561
Return if we should use an adjustable tick locator or a fixed
561562
one. (check is used twice so factored out here...)
562563
"""
563-
return (self.boundaries is None
564-
and self.values is None
565-
and ((type(self.norm) == colors.Normalize)
566-
or (type(self.norm) == colors.LogNorm)))
564+
return ((type(self.norm) == colors.Normalize)
565+
or (type(self.norm) == colors.LogNorm))
567566

568567
def _reset_locator_formatter_scale(self):
569568
"""
@@ -573,13 +572,11 @@ def _reset_locator_formatter_scale(self):
573572
"""
574573
self.locator = None
575574
self.formatter = None
576-
if (isinstance(self.norm, colors.LogNorm)
577-
and self._use_auto_colorbar_locator()):
575+
if (isinstance(self.norm, colors.LogNorm)):
578576
# *both* axes are made log so that determining the
579577
# mid point is easier.
580578
self.ax.set_xscale('log')
581579
self.ax.set_yscale('log')
582-
583580
self.minorticks_on()
584581
else:
585582
self.ax.set_xscale('linear')
@@ -1068,26 +1065,29 @@ def _mesh(self):
10681065
These are suitable for a vertical colorbar; swapping and
10691066
transposition for a horizontal colorbar are done outside
10701067
this function.
1071-
'''
1072-
# if boundaries and values are None, then we can go ahead and
1073-
# scale this up for Auto tick location. Otherwise we
1074-
# want to keep normalized between 0 and 1 and use manual tick
1075-
# locations.
10761068
1069+
These are scaled between vmin and vmax
1070+
'''
1071+
norm = copy.copy(self.norm)
1072+
norm.vmin = self.vmin
1073+
norm.vmax = self.vmax
10771074
x = np.array([0.0, 1.0])
10781075
if self.spacing == 'uniform':
10791076
y = self._uniform_y(self._central_N())
10801077
else:
10811078
y = self._proportional_y()
1082-
if self._use_auto_colorbar_locator():
1083-
y = self.norm.inverse(y)
1084-
x = self.norm.inverse(x)
1079+
xmid = np.array([0.5])
1080+
try:
1081+
y = norm.inverse(y)
1082+
x = norm.inverse(x)
1083+
xmid = norm.inverse(xmid)
1084+
except ValueError:
1085+
dv = self.vmax - self.vmin
1086+
x = x * dv + self.vmin
1087+
y = y * dv + self.vmin
1088+
xmid = xmid * dv + self.vmin
10851089
self._y = y
10861090
X, Y = np.meshgrid(x, y)
1087-
if self._use_auto_colorbar_locator():
1088-
xmid = self.norm.inverse(0.5)
1089-
else:
1090-
xmid = 0.5
10911091
if self._extend_lower() and not self.extendrect:
10921092
X[0, :] = xmid
10931093
if self._extend_upper() and not self.extendrect:

lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ def inverse(self, value):
12531253
BoundaryNorm is not invertible, so calling this method will always
12541254
raise an error
12551255
"""
1256-
return ValueError("BoundaryNorm is not invertible")
1256+
raise ValueError("BoundaryNorm is not invertible")
12571257

12581258

12591259
class NoNorm(Normalize):
Loading

0 commit comments

Comments
 (0)
0