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

Skip to content

Commit 7dc926e

Browse files
committed
Set colorbar label only in set_label.
... instead of doing so also in _config_axis. _config_axis is also called when e.g. the norm is changed, but we don't want to reset the label in that case. Note that the previous `self._labelkw` was only usable for one colorbar orientation anyways (because the choice of `_pos_kw` depends on the orientation) so everything was already tied to a single orientation.
1 parent 8d2c16b commit 7dc926e

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

lib/matplotlib/colorbar.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def _config_axis(self):
548548
ticks_position=self.ticklocation)
549549
short_axis.set_ticks([])
550550
short_axis.set_ticks([], minor=True)
551-
self._set_label()
551+
self.stale = True
552552

553553
def _get_ticker_locator_formatter(self):
554554
"""
@@ -726,16 +726,8 @@ def minorticks_off(self):
726726
"""Turn the minor ticks of the colorbar off."""
727727
ax = self.ax
728728
long_axis = ax.yaxis if self.orientation == 'vertical' else ax.xaxis
729-
730729
long_axis.set_minor_locator(ticker.NullLocator())
731730

732-
def _set_label(self):
733-
if self.orientation == 'vertical':
734-
self.ax.set_ylabel(self._label, **self._labelkw)
735-
else:
736-
self.ax.set_xlabel(self._label, **self._labelkw)
737-
self.stale = True
738-
739731
def set_label(self, label, *, loc=None, **kwargs):
740732
"""Add a label to the long axis of the colorbar."""
741733
_pos_xy = 'y' if self.orientation == 'vertical' else 'x'
@@ -759,9 +751,11 @@ def set_label(self, label, *, loc=None, **kwargs):
759751
elif loc in ['left', 'bottom']:
760752
kwargs[_pos_xy] = 0.
761753
kwargs['horizontalalignment'] = 'left'
762-
self._label = label
763-
self._labelkw = kwargs
764-
self._set_label()
754+
if self.orientation == 'vertical':
755+
self.ax.set_ylabel(label, **kwargs)
756+
else:
757+
self.ax.set_xlabel(label, **kwargs)
758+
self.stale = True
765759

766760
def _outline(self, X, Y):
767761
"""

0 commit comments

Comments
 (0)