MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_colorbar_label

Function test_colorbar_label

lib/matplotlib/tests/test_colorbar.py:726–744  ·  view source on GitHub ↗

Test the label parameter. It should just be mapped to the xlabel/ylabel of the axes, depending on the orientation.

()

Source from the content-addressed store, hash-verified

724
725
726def test_colorbar_label():
727 """
728 Test the label parameter. It should just be mapped to the xlabel/ylabel of
729 the axes, depending on the orientation.
730 """
731 fig, ax = plt.subplots()
732 im = ax.imshow([[1, 2], [3, 4]])
733 cbar = fig.colorbar(im, label='cbar')
734 assert cbar.ax.get_ylabel() == 'cbar'
735 cbar.set_label(None)
736 assert cbar.ax.get_ylabel() == ''
737 cbar.set_label('cbar 2')
738 assert cbar.ax.get_ylabel() == 'cbar 2'
739
740 cbar2 = fig.colorbar(im, label=None)
741 assert cbar2.ax.get_ylabel() == ''
742
743 cbar3 = fig.colorbar(im, orientation='horizontal', label='horizontal cbar')
744 assert cbar3.ax.get_xlabel() == 'horizontal cbar'
745
746
747@image_comparison(['colorbar_keeping_xlabel.png'], style='mpl20')

Callers

nothing calls this directly

Calls 6

imshowMethod · 0.80
get_ylabelMethod · 0.80
get_xlabelMethod · 0.80
subplotsMethod · 0.45
colorbarMethod · 0.45
set_labelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…