Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ def __init__(self, colorbar):
self._colorbar = colorbar
nbins = 'auto'
steps = [1, 2, 2.5, 5, 10]
ticker.MaxNLocator.__init__(self, nbins=nbins, steps=steps)
super().__init__(nbins=nbins, steps=steps)

def tick_values(self, vmin, vmax):
vmin = max(vmin, self._colorbar.norm.vmin)
vmax = min(vmax, self._colorbar.norm.vmax)
ticks = ticker.MaxNLocator.tick_values(self, vmin, vmax)
ticks = super().tick_values(vmin, vmax)
return ticks[(ticks >= vmin) & (ticks <= vmax)]


Expand All @@ -260,12 +260,12 @@ def __init__(self, colorbar, n=None):
"""
self._colorbar = colorbar
self.ndivs = n
ticker.AutoMinorLocator.__init__(self, n=None)
super().__init__(n=None)

def __call__(self):
vmin = self._colorbar.norm.vmin
vmax = self._colorbar.norm.vmax
ticks = ticker.AutoMinorLocator.__call__(self)
ticks = super().__call__()
rtol = (vmax - vmin) * 1e-10
return ticks[(ticks >= vmin - rtol) & (ticks <= vmax + rtol)]

Expand All @@ -290,12 +290,12 @@ def __init__(self, colorbar, *args, **kwargs):
same as `~.ticker.LogLocator`.
"""
self._colorbar = colorbar
ticker.LogLocator.__init__(self, *args, **kwargs)
super().__init__(*args, **kwargs)

def tick_values(self, vmin, vmax):
vmin = self._colorbar.norm.vmin
vmax = self._colorbar.norm.vmax
ticks = ticker.LogLocator.tick_values(self, vmin, vmax)
ticks = super().tick_values(vmin, vmax)
return ticks[(ticks >= vmin) & (ticks <= vmax)]


Expand Down Expand Up @@ -461,7 +461,6 @@ def config_axis(self):
long_axis.set_ticks_position(self.ticklocation)
short_axis.set_ticks([])
short_axis.set_ticks([], minor=True)

self._set_label()

def _get_ticker_locator_formatter(self):
Expand Down Expand Up @@ -536,7 +535,7 @@ def update_ticks(self):
long_axis.set_minor_locator(_ColorbarLogLocator(self,
base=10., subs='auto'))
long_axis.set_minor_formatter(
ticker.LogFormatter()
ticker.LogFormatterSciNotation()
)
else:
_log.debug('Using fixed locator on colorbar')
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,18 @@ def test_colorbar_axes_kw():
plt.imshow(([[1, 2], [3, 4]]))
plt.colorbar(orientation='horizontal', fraction=0.2, pad=0.2, shrink=0.5,
aspect=10, anchor=(0., 0.), panchor=(0., 1.))


def test_colorbar_log_minortick_labels():
with rc_context({'_internal.classic_mode': False}):
fig, ax = plt.subplots()
pcm = ax.imshow([[10000, 50000]], norm=LogNorm())
cb = fig.colorbar(pcm)
fig.canvas.draw()
lb = cb.ax.yaxis.get_ticklabels(which='both')
expected = [r'$\mathdefault{10^{4}}$',
r'$\mathdefault{2\times10^{4}}$',
r'$\mathdefault{3\times10^{4}}$',
r'$\mathdefault{4\times10^{4}}$']
for l, exp in zip(lb, expected):
assert l.get_text() == exp