Skip to content

colorbar(label=None) should give an empty label #14660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def _set_label(self):

def set_label(self, label, **kw):
"""Label the long axis of the colorbar."""
self._label = str(label)
self._label = label
self._labelkw = kw
self._set_label()

Expand Down
21 changes: 21 additions & 0 deletions lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,24 @@ def test_mappable_no_alpha():
fig.colorbar(sm)
sm.set_cmap('plasma')
plt.draw()


def test_colorbar_label():
"""
Test the label parameter. It should just be mapped to the xlabel/ylabel of
the axes, depending on the orientation.
"""
fig, ax = plt.subplots()
im = ax.imshow([[1, 2], [3, 4]])
cbar = fig.colorbar(im, label='cbar')
assert cbar.ax.get_ylabel() == 'cbar'
cbar.set_label(None)
assert cbar.ax.get_ylabel() == ''
cbar.set_label('cbar 2')
assert cbar.ax.get_ylabel() == 'cbar 2'

cbar2 = fig.colorbar(im, label=None)
assert cbar2.ax.get_ylabel() == ''

cbar3 = fig.colorbar(im, orientation='horizontal', label='horizontal cbar')
assert cbar3.ax.get_xlabel() == 'horizontal cbar'