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

Skip to content

Commit 231c502

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

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

lib/matplotlib/axis.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
_gridline_param_names = ['grid_' + name
3333
for name in _line_param_names + _line_param_aliases]
3434

35+
_NoRecursionMarker = object()
36+
3537

3638
class Tick(martist.Artist):
3739
"""
@@ -1225,15 +1227,19 @@ def _set_lim(self, v0, v1, *, emit=True, auto):
12251227
if auto is not None:
12261228
self._set_autoscale_on(bool(auto))
12271229

1230+
# Undocumented internal feature: setting emit to _NoRecursionMarker causes
1231+
# signal emission but doesn't propagate to shared axed (thus preventing
1232+
# infinite recursion).
12281233
if emit:
12291234
self.axes.callbacks.process(f"{name}lim_changed", self.axes)
1230-
# Call all of the other axes that are shared with this one
1231-
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()
1235+
if emit != _NoRecursionMarker:
1236+
# Call all of the other axes that are shared with this one
1237+
for other in self._get_shared_axes():
1238+
if other is not self.axes:
1239+
other._axis_map[name]._set_lim(
1240+
v0, v1, emit=_NoRecursionMarker, auto=auto)
1241+
if other.figure != self.figure:
1242+
other.figure.canvas.draw_idle()
12371243

12381244
self.stale = True
12391245
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)