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

Skip to content

Commit d69b944

Browse files
committed
Emit xlim_changed on shared axes.
1 parent 9333b45 commit d69b944

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
@@ -1229,11 +1229,13 @@ def _set_lim(self, v0, v1, *, emit=True, auto):
12291229
self.axes.callbacks.process(f"{name}lim_changed", self.axes)
12301230
# Call all of the other axes that are shared with this one
12311231
for other in self._get_shared_axes():
1232-
if other is not self.axes:
1233-
other._axis_map[name]._set_lim(
1234-
v0, v1, emit=False, auto=auto)
1235-
if other.figure != self.figure:
1236-
other.figure.canvas.draw_idle()
1232+
if other is self.axes:
1233+
continue
1234+
other._axis_map[name]._set_lim(v0, v1, emit=False, auto=auto)
1235+
if emit:
1236+
other.callbacks.process(f"{name}lim_changed", other)
1237+
if other.figure != self.figure:
1238+
other.figure.canvas.draw_idle()
12371239

12381240
self.stale = True
12391241
return v0, v1

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8704,3 +8704,12 @@ def test_tick_param_labelfont():
87048704
plt.title('Title in sans-serif')
87058705
for text in ax.get_xticklabels():
87068706
assert text.get_fontfamily()[0] == 'monospace'
8707+
8708+
8709+
def test_xylim_changed_shared():
8710+
fig, axs = plt.subplots(2, sharex=True, sharey=True)
8711+
events = []
8712+
axs[1].callbacks.connect("xlim_changed", events.append)
8713+
axs[1].callbacks.connect("ylim_changed", events.append)
8714+
axs[0].set(xlim=[1, 3], ylim=[2, 4])
8715+
assert events == [axs[1], axs[1]]

0 commit comments

Comments
 (0)