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

Skip to content

Commit 9887650

Browse files
committed
Emit xlim_changed on shared axes.
1 parent 2f778fd commit 9887650

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/matplotlib/axis.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Classes for the ticks and x- and y-axis.
33
"""
44

5+
import dataclasses
56
import datetime
67
import functools
78
import logging
@@ -32,6 +33,8 @@
3233
_gridline_param_names = ['grid_' + name
3334
for name in _line_param_names + _line_param_aliases]
3435

36+
_NoRecursionMarker = dataclasses.make_dataclass("_NoRecursionMarker", ["event_src"])
37+
3538

3639
class Tick(martist.Artist):
3740
"""
@@ -1225,13 +1228,17 @@ def _set_lim(self, v0, v1, *, emit=True, auto):
12251228
if auto is not None:
12261229
self._set_autoscale_on(bool(auto))
12271230

1228-
if emit:
1231+
# Undocumented internal feature: emit can be set to _NoRecursionMarker(self),
1232+
# which is treated as True but avoids infinite recursion.
1233+
if emit and emit != _NoRecursionMarker(self):
12291234
self.axes.callbacks.process(f"{name}lim_changed", self.axes)
12301235
# Call all of the other axes that are shared with this one
12311236
for other in self._get_shared_axes():
12321237
if other is not self.axes:
1238+
if not isinstance(emit, _NoRecursionMarker):
1239+
emit = _NoRecursionMarker(self)
12331240
other._axis_map[name]._set_lim(
1234-
v0, v1, emit=False, auto=auto)
1241+
v0, v1, emit=emit, auto=auto)
12351242
if other.figure != self.figure:
12361243
other.figure.canvas.draw_idle()
12371244

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)