Skip to content

Commit ad7007b

Browse files
committed
FIX: do not reset ylabel ha when changing position
closes #18427
1 parent 5b835ee commit ad7007b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/matplotlib/axis.py

-1
Original file line numberDiff line numberDiff line change
@@ -2339,7 +2339,6 @@ def set_label_position(self, position):
23392339
position : {'left', 'right'}
23402340
"""
23412341
self.label.set_rotation_mode('anchor')
2342-
self.label.set_horizontalalignment('center')
23432342
self.label.set_verticalalignment(_api.check_getitem({
23442343
'left': 'bottom', 'right': 'top',
23452344
}, position=position))

lib/matplotlib/tests/test_axes.py

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
image_comparison, check_figures_equal, remove_ticks_and_titles)
2424
import matplotlib.colors as mcolors
2525
import matplotlib.dates as mdates
26+
from matplotlib.figure import Figure
2627
import matplotlib.font_manager as mfont_manager
2728
import matplotlib.markers as mmarkers
2829
import matplotlib.patches as mpatches
@@ -6758,3 +6759,12 @@ def test_2dcolor_plot(fig_test, fig_ref):
67586759
axs[2].step([1, 2], [1, 2], c=color.reshape((1, -1)))
67596760
axs[3].hist(np.arange(10), color=color.reshape((1, -1)))
67606761
axs[4].bar(np.arange(10), np.arange(10), color=color.reshape((1, -1)))
6762+
6763+
6764+
@pytest.mark.parametrize('ha', ['left', 'center', 'right'])
6765+
def test_ylabel_ha_with_position(ha):
6766+
fig = Figure()
6767+
ax = fig.subplots()
6768+
ax.set_ylabel("test", y=1, ha=ha)
6769+
ax.yaxis.set_label_position("right")
6770+
assert ax.yaxis.get_label().get_ha() == ha

0 commit comments

Comments
 (0)