Fix SpanSelector interactive mode forcing axes limits to include 0 #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



The SpanSelector widget was incorrectly expanding axes limits to include 0 when created with
interactive=True, even when the plotted data didn't include 0. This regression affected the expected behavior where axes limits should remain focused on the actual data range.Problem
When creating a SpanSelector with
interactive=True:The axes xlimits were being expanded to include x=0, which was not the case in Matplotlib 3.4 with the old
span_staysparameter.Root Cause
When
interactive=True, SpanSelector creates interactive handles viaToolLineHandlesat initialization. These handles were positioned usingself.extents, which returns(0, 0)from the initially created Rectangle at origin. This causedaxvline(0)calls that forced the axes to include x=0, even though the handles were invisible.Solution
Modified
_setup_edge_handleto use current axes limits (ax.get_xlim()orax.get_ylim()) as initial handle positions instead ofself.extents. This prevents unwanted axes expansion while maintaining all interactive functionality.The key change ensures handles are created within existing axes bounds:
After user interaction, handles are updated to correct positions via the normal
extents.settermechanism, preserving all existing behavior.Fixes #1.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.