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

Skip to content

Commit 6ba23b8

Browse files
committed
Turn minorticks on for Log Colorbar only on initialization or full reset
Fixes issue where colorbar lognorm minorticks are turned back on anytime ticks are updated
1 parent 9c1d70b commit 6ba23b8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/matplotlib/colorbar.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,10 @@ def _reset_locator_formatter_scale(self):
579579
# mid point is easier.
580580
self.ax.set_xscale('log')
581581
self.ax.set_yscale('log')
582+
583+
if type(self.norm) == colors.LogNorm:
584+
self.minorticks_on()
585+
582586
else:
583587
self.ax.set_xscale('linear')
584588
self.ax.set_yscale('linear')
@@ -602,8 +606,6 @@ def update_ticks(self):
602606
_log.debug('locator: %r', locator)
603607
long_axis.set_major_locator(locator)
604608
long_axis.set_major_formatter(formatter)
605-
if type(self.norm) == colors.LogNorm:
606-
self.minorticks_on()
607609
else:
608610
_log.debug('Using fixed locator on colorbar')
609611
ticks, ticklabels, offset_string = self._ticker(locator, formatter)

lib/matplotlib/tests/test_colorbar.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ def test_colorbar_minorticks_on_off():
325325
assert np.array_equal(cbar.ax.yaxis.get_minorticklocs(),
326326
default_minorticklocks)
327327

328+
# test issue #13339: minorticks for LogNorm should stay off
329+
cbar.minorticks_off()
330+
cbar.set_ticks([3, 5, 7, 9])
331+
assert np.array_equal(cbar.ax.yaxis.get_minorticklocs(),
332+
np.array([]))
333+
328334

329335
def test_colorbar_autoticks():
330336
# Test new autotick modes. Needs to be classic because

0 commit comments

Comments
 (0)