Skip to content
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

Backport PR #20826 on branch v3.4.x (Fix clear of Axes that are shared.) #20830

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/matplotlib/axis.py
Expand Up @@ -791,8 +791,13 @@ def clear(self):
# Clear the callback registry for this axis, or it may "leak"
self.callbacks = cbook.CallbackRegistry()

self._reset_major_tick_kw()
self._reset_minor_tick_kw()
# whether the grids are on
self._major_tick_kw['gridOn'] = (
mpl.rcParams['axes.grid'] and
mpl.rcParams['axes.grid.which'] in ('both', 'major'))
self._minor_tick_kw['gridOn'] = (
mpl.rcParams['axes.grid'] and
mpl.rcParams['axes.grid.which'] in ('both', 'minor'))
self.reset_ticks()

self.converter = None
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Expand Up @@ -6955,6 +6955,21 @@ def test_2dcolor_plot(fig_test, fig_ref):
axs[4].bar(np.arange(10), np.arange(10), color=color.reshape((1, -1)))


@check_figures_equal(extensions=['png'])
def test_shared_axes_clear(fig_test, fig_ref):
x = np.arange(0.0, 2*np.pi, 0.01)
y = np.sin(x)

axs = fig_ref.subplots(2, 2, sharex=True, sharey=True)
for ax in axs.flat:
ax.plot(x, y)

axs = fig_test.subplots(2, 2, sharex=True, sharey=True)
for ax in axs.flat:
ax.clear()
ax.plot(x, y)


def test_shared_axes_retick():
fig, axs = plt.subplots(2, 2, sharex='all', sharey='all')

Expand Down