Skip to content

Commit

Permalink
Merge pull request #20830 from meeseeksmachine/auto-backport-of-pr-20…
Browse files Browse the repository at this point in the history
…826-on-v3.4.x

Backport PR #20826 on branch v3.4.x (Fix clear of Axes that are shared.)
  • Loading branch information
QuLogic committed Aug 12, 2021
2 parents da6b1fe + 4b5ea5a commit c946d3c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit c946d3c

Please sign in to comment.