Sync shared limits without callbacks by samiat4911 · Pull Request #31905 · matplotlib/matplotlib
PR summary
Shared axes now remain synchronized when axis limits are changed with
emit=False.
Previously, Axis._set_lim() used emit to control both callback emission and
shared-axis limit propagation. As a result, calls such as:
fig, axs = plt.subplots(1, 2, sharex=True) axs[0].set_xlim(0, 0.1, emit=False)
updated only the first Axes. The shared Axes retained different limits while
using the same tick locator, which could produce incorrect tick positions.
This change separates shared-axis propagation from callback emission by adding
an internal propagation flag. The initiating call updates every shared Axes,
while propagated updates disable further propagation to prevent infinite
recursion. emit=False continues to suppress limit-change callbacks.
The existing shared-axis callback test now also verifies that:
- x and y limits propagate to every Axes in a shared group when
emit=False; - no callbacks are emitted by either the initiating or shared Axes.
This follows the design discussion in #26011.
Closes #26085
AI Disclosure
OpenAI Codex was used to implement the fix, add regression coverage, run available validation. The changes were reviewed and validated with local static checks and runtime smoke tests.
PR checklist
- "closes [Bug]: Should Axes.set_xlim(..., emit=False) really not sync shared axes? #26085" is in the body of the PR description
- new and changed code is tested
- [N/A] Plotting related features are demonstrated in an example
- [N/A] New Features and API Changes are noted with a directive and release note
- [N/A] Documentation complies with general and docstring guidelines