FIX Update Axes limits from Axes.add_collection(... autolim=True)#30327
Merged
tacaswell merged 1 commit intomatplotlib:mainfrom Jul 24, 2025
Merged
FIX Update Axes limits from Axes.add_collection(... autolim=True)#30327tacaswell merged 1 commit intomatplotlib:mainfrom
tacaswell merged 1 commit intomatplotlib:mainfrom
Conversation
timhoffm
commented
Jul 17, 2025
Comment on lines
+904
to
+919
| # sample data to give initial data limits | ||
| ax.plot([2, 3, 4], [0.4, 0.6, 0.5]) | ||
| np.testing.assert_allclose((ax.dataLim.xmin, ax.dataLim.xmax), (2, 4)) | ||
| data_ymin, data_ymax = ax.dataLim.ymin, ax.dataLim.ymax | ||
|
|
||
| f, ax = plt.subplots() | ||
| # LineCollection with vertical lines spanning the Axes vertical, using transAxes | ||
| x = [1, 2, 3, 4, 5] | ||
| vertical_lines = [np.array([[xi, 0], [xi, 1]]) for xi in x] | ||
| trans = mtransforms.blended_transform_factory(ax.transData, ax.transAxes) | ||
| ax.add_collection(LineCollection(line_segs, transform=trans)) | ||
| ax.autoscale_view(scalex=True, scaley=False) | ||
| np.testing.assert_allclose(ax.get_xlim(), [1., 4.]) | ||
| ax.add_collection(LineCollection(vertical_lines, transform=trans)) | ||
|
|
||
| # check that the x data limits are updated to include the LineCollection | ||
| np.testing.assert_allclose((ax.dataLim.xmin, ax.dataLim.xmax), (1, 5)) | ||
| # check that the y data limits are not updated (because they are not transData) | ||
| np.testing.assert_allclose((ax.dataLim.ymin, ax.dataLim.ymax), (0.4, 0.6)) |
Member
Author
There was a problem hiding this comment.
Note 1: Before, the test did only check that the x data limits were expanded. It did not investigate the y data limits. Now it also ensures, that y data limits are not changed.
Note 2: I've switched from testing view limits to testing data limits, because that's the relevant quantity autolim influences. We save the autoscale_view() by not looking at the view limits.
rcomer
reviewed
Jul 19, 2025
Member
|
I should have looked at the CI before I looked at the code 🤦♀️ |
Member
|
This breaks |
Member
Author
|
Good point! We must update if either the transform or the offset transform use data coordinates. -> Fixed. |
rcomer
reviewed
Jul 21, 2025
... the update now happens separately for both directions, and only if that direction uses data coordinates. Previously, limits were always recalculated for both directions. Closes matplotlib#30320.
rcomer
approved these changes
Jul 21, 2025
meeseeksmachine
pushed a commit
to meeseeksmachine/matplotlib
that referenced
this pull request
Jul 24, 2025
…llection(... autolim=True)
timhoffm
pushed a commit
that referenced
this pull request
Jul 25, 2025
….. autolim=True) (#30351) Co-authored-by: Thomas A Caswell <tcaswell@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 update now happens separately for both directions, and only if that direction uses data coordinates. Previously, limits were always recalculated for both directions.
Closes #30320.