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

Skip to content

Commit 825f518

Browse files
authored
Merge pull request #18645 from anntzer/cbar
Simplify Colorbar.set_label, inline Colorbar._edges.
2 parents 80c40b8 + e97bb70 commit 825f518

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

lib/matplotlib/colorbar.py

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -766,39 +766,12 @@ def set_label(self, label, *, loc=None, **kwargs):
766766
`~.Axes.set_ylabel`.
767767
Supported keywords are *labelpad* and `.Text` properties.
768768
"""
769-
_pos_xy = 'y' if self.orientation == 'vertical' else 'x'
770-
_protected_kw = [_pos_xy, 'horizontalalignment', 'ha']
771-
if any([k in kwargs for k in _protected_kw]):
772-
if loc is not None:
773-
raise TypeError(f'Specifying *loc* is disallowed when any of '
774-
f'its corresponding low level keyword '
775-
f'arguments {_protected_kw} are also supplied')
776-
loc = 'center'
769+
if self.orientation == "vertical":
770+
self.ax.set_ylabel(label, loc=loc, **kwargs)
777771
else:
778-
if loc is None:
779-
loc = mpl.rcParams['%saxis.labellocation' % _pos_xy]
780-
if self.orientation == 'vertical':
781-
_api.check_in_list(('bottom', 'center', 'top'), loc=loc)
782-
else:
783-
_api.check_in_list(('left', 'center', 'right'), loc=loc)
784-
if loc in ['right', 'top']:
785-
kwargs[_pos_xy] = 1.
786-
kwargs['horizontalalignment'] = 'right'
787-
elif loc in ['left', 'bottom']:
788-
kwargs[_pos_xy] = 0.
789-
kwargs['horizontalalignment'] = 'left'
790-
if self.orientation == 'vertical':
791-
self.ax.set_ylabel(label, **kwargs)
792-
else:
793-
self.ax.set_xlabel(label, **kwargs)
772+
self.ax.set_xlabel(label, loc=loc, **kwargs)
794773
self.stale = True
795774

796-
def _edges(self, X, Y):
797-
"""Return the separator line segments; helper for _add_solids."""
798-
# Using the non-array form of these line segments is much
799-
# simpler than making them into arrays.
800-
return [list(zip(X[i], Y[i])) for i in range(1, len(X) - 1)]
801-
802775
def _add_solids(self, X, Y, C):
803776
"""Draw the colors; optionally add separators."""
804777
# Cleanup previously set artists.
@@ -814,7 +787,8 @@ def _add_solids(self, X, Y, C):
814787
self._add_solids_patches(X, Y, C, mappable)
815788
else:
816789
self._add_solids_pcolormesh(X, Y, C)
817-
self.dividers.set_segments(self._edges(X, Y) if self.drawedges else [])
790+
self.dividers.set_segments(
791+
np.dstack([X, Y])[1:-1] if self.drawedges else [])
818792

819793
def _add_solids_pcolormesh(self, X, Y, C):
820794
_log.debug('Setting pcolormesh')

0 commit comments

Comments
 (0)