Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e24001

Browse files
committed
FIX: properly fallback bad scale
1 parent 7a2971b commit 0e24001

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lib/matplotlib/colorbar.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ def __init__(self, ax, cmap=None,
452452
self.locator = None
453453
self.formatter = None
454454
self._manual_tick_data_values = None
455+
self.__scale = None # linear, log10 for now. Hopefully more?
455456

456457
if ticklocation == 'auto':
457458
ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
@@ -585,8 +586,8 @@ def _use_auto_colorbar_locator(self):
585586
one. (check is used twice so factored out here...)
586587
"""
587588
contouring = self.boundaries is not None and self.spacing == 'uniform'
588-
return (type(self.norm) in [colors.Normalize, colors.LogNorm]
589-
and not contouring)
589+
return (type(self.norm) in [colors.Normalize, colors.LogNorm] and
590+
not contouring)
590591

591592
def _reset_locator_formatter_scale(self):
592593
"""
@@ -602,9 +603,14 @@ def _reset_locator_formatter_scale(self):
602603
self.ax.set_xscale('log')
603604
self.ax.set_yscale('log')
604605
self.minorticks_on()
606+
self.__scale = 'log'
605607
else:
606608
self.ax.set_xscale('linear')
607609
self.ax.set_yscale('linear')
610+
if type(self.norm) is colors.Normalize:
611+
self.__scale = 'linear'
612+
else:
613+
self.__scale = 'manual'
608614

609615
def update_ticks(self):
610616
"""
@@ -1119,13 +1125,13 @@ def _mesh(self):
11191125
else:
11201126
y = self._proportional_y()
11211127
xmid = np.array([0.5])
1122-
try:
1128+
if self.__scale != 'manual':
11231129
y = norm.inverse(y)
11241130
x = norm.inverse(x)
11251131
xmid = norm.inverse(xmid)
1126-
except ValueError:
1127-
# occurs for norms that don't have an inverse, in
1128-
# which case manually scale:
1132+
else:
1133+
# if a norm doesn't have a named scale, or
1134+
# we are not using a norm
11291135
dv = self.vmax - self.vmin
11301136
x = x * dv + self.vmin
11311137
y = y * dv + self.vmin

lib/matplotlib/tests/test_colorbar.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ def test_colorbar_get_ticks():
373373
data = np.arange(1200).reshape(30, 40)
374374
levels = [0, 200, 400, 600, 800, 1000, 1200]
375375

376-
plt.subplot()
377376
plt.contourf(data, levels=levels)
378377

379378
# testing getter for user set ticks

0 commit comments

Comments
 (0)