Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,13 @@ def __clear(self):
xaxis_visible = self.xaxis.get_visible()
yaxis_visible = self.yaxis.get_visible()

for axis in self._axis_map.values():
for name, axis in self._axis_map.items():
axis.clear() # Also resets the scale to linear.
# need to do any shared axis scales as well
for other in axis._get_shared_axes():
if other is self.axes:
continue
other._axis_map[name]._set_scale("linear")
for spine in self.spines.values():
spine._clear() # Use _clear to not clear Axis again

Expand Down
19 changes: 19 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from matplotlib.projections.geo import HammerAxes
from matplotlib.projections.polar import PolarAxes
import matplotlib.pyplot as plt
import matplotlib.scale as mscales
import matplotlib.text as mtext
import matplotlib.ticker as mticker
import matplotlib.transforms as mtransforms
Expand Down Expand Up @@ -9308,6 +9309,24 @@ def test_shared_axes_clear(fig_test, fig_ref):
ax.plot(x, y)


def test_shared_axes_clear_scale(recwarn):
_, axs = plt.subplots(1, 2, sharey=True)
x = range(1, 10)
axs[0].loglog(x, x)
axs[1].loglog(x, x)
axs[0].clear()

assert len(recwarn) == 0

# the cleared axes has linear on both axis
for axis in axs[0]._axis_map.values():
assert isinstance(axis._scale, mscales.LinearScale)

# the linked axes becomes linear on the shared y-axis
assert isinstance(axs[1].xaxis._scale, mscales.LogScale)
assert isinstance(axs[1].yaxis._scale, mscales.LinearScale)


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

Expand Down
Loading