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

Skip to content

Commit c2e09e8

Browse files
authored
Merge pull request #17806 from anntzer/eagercbarlabel
MNT: Set colorbar label only in set_label.
2 parents 5e11a23 + 7dc926e commit c2e09e8

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

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
"""
741733
Add a label to the long axis of the colorbar.
@@ -778,9 +770,11 @@ def set_label(self, label, *, loc=None, **kwargs):
778770
elif loc in ['left', 'bottom']:
779771
kwargs[_pos_xy] = 0.
780772
kwargs['horizontalalignment'] = 'left'
781-
self._label = label
782-
self._labelkw = kwargs
783-
self._set_label()
773+
if self.orientation == 'vertical':
774+
self.ax.set_ylabel(label, **kwargs)
775+
else:
776+
self.ax.set_xlabel(label, **kwargs)
777+
self.stale = True
784778

785779
def _outline(self, X, Y):
786780
"""

0 commit comments

Comments
 (0)