Skip to content

Commit c946d3c

Browse files
authored
Merge pull request #20830 from meeseeksmachine/auto-backport-of-pr-20826-on-v3.4.x
Backport PR #20826 on branch v3.4.x (Fix clear of Axes that are shared.)
2 parents da6b1fe + 4b5ea5a commit c946d3c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/matplotlib/axis.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,13 @@ def clear(self):
791791
# Clear the callback registry for this axis, or it may "leak"
792792
self.callbacks = cbook.CallbackRegistry()
793793

794-
self._reset_major_tick_kw()
795-
self._reset_minor_tick_kw()
794+
# whether the grids are on
795+
self._major_tick_kw['gridOn'] = (
796+
mpl.rcParams['axes.grid'] and
797+
mpl.rcParams['axes.grid.which'] in ('both', 'major'))
798+
self._minor_tick_kw['gridOn'] = (
799+
mpl.rcParams['axes.grid'] and
800+
mpl.rcParams['axes.grid.which'] in ('both', 'minor'))
796801
self.reset_ticks()
797802

798803
self.converter = None

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6955,6 +6955,21 @@ def test_2dcolor_plot(fig_test, fig_ref):
69556955
axs[4].bar(np.arange(10), np.arange(10), color=color.reshape((1, -1)))
69566956

69576957

6958+
@check_figures_equal(extensions=['png'])
6959+
def test_shared_axes_clear(fig_test, fig_ref):
6960+
x = np.arange(0.0, 2*np.pi, 0.01)
6961+
y = np.sin(x)
6962+
6963+
axs = fig_ref.subplots(2, 2, sharex=True, sharey=True)
6964+
for ax in axs.flat:
6965+
ax.plot(x, y)
6966+
6967+
axs = fig_test.subplots(2, 2, sharex=True, sharey=True)
6968+
for ax in axs.flat:
6969+
ax.clear()
6970+
ax.plot(x, y)
6971+
6972+
69586973
def test_shared_axes_retick():
69596974
fig, axs = plt.subplots(2, 2, sharex='all', sharey='all')
69606975

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy