Skip to content

Commit 46e6353

Browse files
authored
Merge pull request matplotlib#32090 from meeseeksmachine/auto-backport-of-pr-32069-on-v3.11.x
Backport PR matplotlib#32069 on branch v3.11.x (FIX: remove warning when clearing axes with shared axis)
2 parents ef1f266 + 16175a8 commit 46e6353

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,8 +1354,13 @@ def __clear(self):
13541354
xaxis_visible = self.xaxis.get_visible()
13551355
yaxis_visible = self.yaxis.get_visible()
13561356

1357-
for axis in self._axis_map.values():
1357+
for name, axis in self._axis_map.items():
13581358
axis.clear() # Also resets the scale to linear.
1359+
# need to do any shared axis scales as well
1360+
for other in axis._get_shared_axes():
1361+
if other is self.axes:
1362+
continue
1363+
other._axis_map[name]._set_scale("linear")
13591364
for spine in self.spines.values():
13601365
spine._clear() # Use _clear to not clear Axis again
13611366

lib/matplotlib/tests/test_axes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from matplotlib.projections.geo import HammerAxes
3838
from matplotlib.projections.polar import PolarAxes
3939
import matplotlib.pyplot as plt
40+
import matplotlib.scale as mscales
4041
import matplotlib.text as mtext
4142
import matplotlib.ticker as mticker
4243
import matplotlib.transforms as mtransforms
@@ -9264,6 +9265,24 @@ def test_shared_axes_clear(fig_test, fig_ref):
92649265
ax.plot(x, y)
92659266

92669267

9268+
def test_shared_axes_clear_scale(recwarn):
9269+
_, axs = plt.subplots(1, 2, sharey=True)
9270+
x = range(1, 10)
9271+
axs[0].loglog(x, x)
9272+
axs[1].loglog(x, x)
9273+
axs[0].clear()
9274+
9275+
assert len(recwarn) == 0
9276+
9277+
# the cleared axes has linear on both axis
9278+
for axis in axs[0]._axis_map.values():
9279+
assert isinstance(axis._scale, mscales.LinearScale)
9280+
9281+
# the linked axes becomes linear on the shared y-axis
9282+
assert isinstance(axs[1].xaxis._scale, mscales.LogScale)
9283+
assert isinstance(axs[1].yaxis._scale, mscales.LinearScale)
9284+
9285+
92679286
def test_shared_axes_retick():
92689287
fig, axs = plt.subplots(2, 2, sharex='all', sharey='all')
92699288

0 commit comments

Comments
 (0)