diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 6655f2bab276..ce506b018e63 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1241,11 +1241,13 @@ def _set_lim(self, v0, v1, *, emit=True, auto): self.axes.callbacks.process(f"{name}lim_changed", self.axes) # Call all of the other axes that are shared with this one for other in self._get_shared_axes(): - if other is not self.axes: - other._axis_map[name]._set_lim( - v0, v1, emit=False, auto=auto) - if other.figure != self.figure: - other.figure.canvas.draw_idle() + if other is self.axes: + continue + other._axis_map[name]._set_lim(v0, v1, emit=False, auto=auto) + if emit: + other.callbacks.process(f"{name}lim_changed", other) + if other.figure != self.figure: + other.figure.canvas.draw_idle() self.stale = True return v0, v1 diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 947c706e900f..b0358cc97442 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -8794,3 +8794,12 @@ def test_set_secondary_axis_color(): assert mcolors.same_color(sax.xaxis.get_tick_params()["color"], "red") assert mcolors.same_color(sax.xaxis.get_tick_params()["labelcolor"], "red") assert mcolors.same_color(sax.xaxis.label.get_color(), "red") + + +def test_xylim_changed_shared(): + fig, axs = plt.subplots(2, sharex=True, sharey=True) + events = [] + axs[1].callbacks.connect("xlim_changed", events.append) + axs[1].callbacks.connect("ylim_changed", events.append) + axs[0].set(xlim=[1, 3], ylim=[2, 4]) + assert events == [axs[1], axs[1]]