Skip to content

Commit 33376e9

Browse files
authored
Merge pull request #14660 from timhoffm/colorbar-label-none
colorbar(label=None) should give an empty label
2 parents 72d6bed + 02f25d6 commit 33376e9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def _set_label(self):
724724

725725
def set_label(self, label, **kw):
726726
"""Label the long axis of the colorbar."""
727-
self._label = str(label)
727+
self._label = label
728728
self._labelkw = kw
729729
self._set_label()
730730

lib/matplotlib/tests/test_colorbar.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,24 @@ def test_mappable_no_alpha():
559559
fig.colorbar(sm)
560560
sm.set_cmap('plasma')
561561
plt.draw()
562+
563+
564+
def test_colorbar_label():
565+
"""
566+
Test the label parameter. It should just be mapped to the xlabel/ylabel of
567+
the axes, depending on the orientation.
568+
"""
569+
fig, ax = plt.subplots()
570+
im = ax.imshow([[1, 2], [3, 4]])
571+
cbar = fig.colorbar(im, label='cbar')
572+
assert cbar.ax.get_ylabel() == 'cbar'
573+
cbar.set_label(None)
574+
assert cbar.ax.get_ylabel() == ''
575+
cbar.set_label('cbar 2')
576+
assert cbar.ax.get_ylabel() == 'cbar 2'
577+
578+
cbar2 = fig.colorbar(im, label=None)
579+
assert cbar2.ax.get_ylabel() == ''
580+
581+
cbar3 = fig.colorbar(im, orientation='horizontal', label='horizontal cbar')
582+
assert cbar3.ax.get_xlabel() == 'horizontal cbar'

0 commit comments

Comments
 (0)