Skip to content

Commit c304045

Browse files
committed
Ensure all params are restored after reset_ticks.
Currently, only label rotation was broken, but I set up the test to check everything. Fixes matplotlib#20791.
1 parent 9a7329c commit c304045

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/matplotlib/axis.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ def __init__(self, axes, loc, *,
167167
GRIDLINE_INTERPOLATION_STEPS
168168
self.label1 = mtext.Text(
169169
np.nan, np.nan,
170-
fontsize=labelsize, color=labelcolor, visible=label1On)
170+
fontsize=labelsize, color=labelcolor, visible=label1On,
171+
rotation=self._labelrotation[1])
171172
self.label2 = mtext.Text(
172173
np.nan, np.nan,
173-
fontsize=labelsize, color=labelcolor, visible=label2On)
174+
fontsize=labelsize, color=labelcolor, visible=label2On,
175+
rotation=self._labelrotation[1])
174176

175177
self._apply_tickdir(tickdir)
176178

lib/matplotlib/tests/test_axes.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4779,6 +4779,26 @@ def test_reset_grid():
47794779
assert ax.xaxis.majorTicks[0].gridline.get_visible()
47804780

47814781

4782+
@check_figures_equal(extensions=['png'])
4783+
def test_reset_ticks(fig_test, fig_ref):
4784+
for fig in [fig_ref, fig_test]:
4785+
ax = fig.add_subplot()
4786+
ax.grid(True)
4787+
ax.tick_params(
4788+
direction='in', length=10, width=5, color='C0', pad=12,
4789+
labelsize=14, labelcolor='C1', labelrotation=45,
4790+
grid_color='C2', grid_alpha=0.8, grid_linewidth=3,
4791+
grid_linestyle='--')
4792+
fig.draw_no_output()
4793+
4794+
# After we've changed any setting on ticks, reset_ticks will mean
4795+
# re-creating them from scratch. This *should* appear the same as not
4796+
# resetting them.
4797+
for ax in fig_test.axes:
4798+
ax.xaxis.reset_ticks()
4799+
ax.yaxis.reset_ticks()
4800+
4801+
47824802
def test_vline_limit():
47834803
fig = plt.figure()
47844804
ax = fig.gca()

0 commit comments

Comments
 (0)