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

Skip to content

Commit 968ab3e

Browse files
committed
FIX: fix error in colorbar.get_ticks not having valid data
1 parent ad779b4 commit 968ab3e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/matplotlib/colorbar.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ def __init__(self, ax, cmap=None,
386386
self.outline = None
387387
self.patch = None
388388
self.dividers = None
389+
self._manual_tick_data_values = None
389390

390391
if ticklocation == 'auto':
391392
ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
@@ -573,7 +574,17 @@ def set_ticks(self, ticks, update_ticks=True):
573574

574575
def get_ticks(self, minor=False):
575576
"""Return the x ticks as a list of locations"""
576-
return self._tick_data_values
577+
if self._manual_tick_data_values is None:
578+
ax = self.ax
579+
if self.orientation == 'vertical':
580+
long_axis, short_axis = ax.yaxis, ax.xaxis
581+
else:
582+
long_axis, short_axis = ax.xaxis, ax.yaxis
583+
return long_axis.get_majorticklocs()
584+
else:
585+
# We made the axes manually, the old way, and the ylim is 0-1,
586+
# so the majorticklocs are in those units, not data units.
587+
return self._manual_tick_data_values
577588

578589
def set_ticklabels(self, ticklabels, update_ticks=True):
579590
"""
@@ -755,7 +766,7 @@ def _ticker(self, locator, formatter):
755766
else:
756767
eps = (intv[1] - intv[0]) * 1e-10
757768
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
758-
self._tick_data_values = b
769+
self._manual_tick_data_values = b
759770
ticks = self._locate(b)
760771
formatter.set_locs(b)
761772
ticklabels = [formatter(t, i) for i, t in enumerate(b)]

0 commit comments

Comments
 (0)