8000 fix · matplotlib/matplotlib@b2f2e20 · GitHub
[go: up one dir, main page]

Skip to content

Commit b2f2e20

Browse filesBrowse files
committed
fix
1 parent 9e44bf9 commit b2f2e20

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

lib/matplotlib/colorbar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def _set_label(self):
739739
self.ax.set_xlabel(self._label, **self._labelkw)
740740
self.stale = True
741741

742-
def set_label(self, label, *, loc=None, **kw):
742+
def set_label(self, label, *, loc=None, **kwargs):
743743
"""Add a label to the long axis of the colorbar."""
744744
_pos_xy = 'y' if self.orientation == 'vertical' else 'x'
745745
_protected_kw = [_pos_xy, 'horizontalalignment', 'ha']
@@ -755,15 +755,15 @@ def set_label(self, label, *, loc=None, **kw):
755755
if self.orientation == 'vertical':
756756
cbook._check_in_list(('bottom', 'center', 'top'), loc=loc)
757757
else:
758-
cbook._check_in_list(('left', 'center', 'top'), loc=loc)
758+
cbook._check_in_list(('left', 'center', 'right'), loc=loc)
759759
if loc in ['right', 'top']:
760760
kwargs[_pos_xy] = 1.
761761
kwargs['horizontalalignment'] = 'right'
762762
elif loc in ['left', 'bottom']:
763763
kwargs[_pos_xy] = 0.
764764
kwargs['horizontalalignment'] = 'left'
765765
self._label = label
766-
self._labelkw = kw
766+
self._labelkw = kwargs
767767
self._set_label()
768768

769769
def _outline(self, X, Y):

lib/matplotlib/tests/test_axes.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,59 @@ def test_get_labels():
4242
assert ax.get_ylabel() == 'y label'
4343

4444

45+
@check_figures_equal()
46+
def test_label_loc_vertical(fig_test, fig_ref):
47+
ax = fig_test.subplots()
48+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
49+
ax.set_ylabel('YLabel', loc='top')
50+
ax.set_xlabel('XLabel', loc='right')
51+
cbar = fig_test.colorbar(sc)
52+
10000 cbar.set_label("ZLabel", loc='top')
53+
54+
ax = fig_ref.subplots()
55+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
56+
ax.set_ylabel('YLabel', y=1, ha='right')
57+
ax.set_xlabel('XLabel', x=1, ha='right')
58+
cbar = fig_ref.colorbar(sc)
59+
cbar.set_label("ZLabel", y=1, ha='right')
60+
61+
62+
@check_figures_equal()
63+
def test_label_loc_horizontal(fig_test, fig_ref):
64+
ax = fig_test.subplots()
65+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
66+
ax.set_ylabel('YLabel', loc='bottom')
67+
ax.set_xlabel('XLabel', loc='left')
68+
cbar = fig_test.colorbar(sc, orientation='horizontal')
69+
cbar.set_label("ZLabel", loc='left')
70+
71+
ax = fig_ref.subplots()
72+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
73+
ax.set_ylabel('YLabel', y=0, ha='left')
74+
ax.set_xlabel('XLabel', x=0, ha='left')
75+
cbar = fig_ref.colorbar(sc, orientation='horizontal')
76+
cbar.set_label("ZLabel", x=0, ha='left')
77+
78+
79+
@check_figures_equal()
80+
def test_label_loc_rc(fig_test, fig_ref):
81+
with matplotlib.rc_context({"xaxis.labellocation": "right",
82+
"yaxis.labellocation": "top"}):
83+
ax = fig_test.subplots()
84+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
85+
ax.set_ylabel('YLabel')
86+
ax.set_xlabel('XLabel')
87+
cbar = fig_test.colorbar(sc, orientation='horizontal')
88+
cbar.set_label("ZLabel")
89+
90+
ax = fig_ref.subplots()
91+
sc = ax.scatter([1, 2], [1, 2], c=[1, 2])
92+
ax.set_ylabel('YLabel', y=1, ha='right')
93+
ax.set_xlabel('XLabel', x=1, ha='right')
94+
cbar = fig_ref.colorbar(sc, orientation='horizontal')
95+
cbar.set_label("ZLabel", x=1, ha='right')
96+
97+
4598
@image_comparison(['acorr.png'], style='mpl20')
4699
def test_acorr():
47100
# Remove this line when this test image is regenerated.

0 commit comments

Comments
 (0)
0