Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ace1d5

Browse files
committed
Emit xlim_changed on shared axes.
1 parent 6391678 commit 5ace1d5

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/matplotlib/axis.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,11 +1241,13 @@ def _set_lim(self, v0, v1, *, emit=True, auto):
12411241
self.axes.callbacks.process(f"{name}lim_changed", self.axes)
12421242
# Call all of the other axes that are shared with this one
12431243
for other in self._get_shared_axes():
1244-
if other is not self.axes:
1245-
other._axis_map[name]._set_lim(
1246-
v0, v1, emit=False, auto=auto)
1247-
if other.figure != self.figure:
1248-
other.figure.canvas.draw_idle()
1244+
if other is self.axes:
1245+
continue
1246+
other._axis_map[name]._set_lim(v0, v1, emit=False, auto=auto)
1247+
if emit:
1248+
other.callbacks.process(f"{name}lim_changed", other)
1249+
if other.figure != self.figure:
1250+
other.figure.canvas.draw_idle()
12491251

12501252
self.stale = True
12511253
return v0, v1

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8794,3 +8794,12 @@ def test_set_secondary_axis_color():
87948794
assert mcolors.same_color(sax.xaxis.get_tick_params()["color"], "red")
87958795
assert mcolors.same_color(sax.xaxis.get_tick_params()["labelcolor"], "red")
87968796
assert mcolors.same_color(sax.xaxis.label.get_color(), "red")
8797+
8798+
8799+
def test_xylim_changed_shared():
8800+
fig, axs = plt.subplots(2, sharex=True, sharey=True)
8801+
events = []
8802+
axs[1].callbacks.connect("xlim_changed", events.append)
8803+
axs[1].callbacks.connect("ylim_changed", events.append)
8804+
axs[0].set(xlim=[1, 3], ylim=[2, 4])
8805+
assert events == [axs[1], axs[1]]

0 commit comments

Comments
 (0)