Content-Length: 353454 | pFad | http://github.com/matplotlib/matplotlib/pull/30327

AD FIX Update Axes limits from Axes.add_collection(... autolim=True) by timhoffm · Pull Request #30327 · matplotlib/matplotlib · GitHub
Skip to content

FIX Update Axes limits from Axes.add_collection(... autolim=True) #30327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025

Conversation

timhoffm
Copy link
Member

... 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.

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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

rcomer commented Jul 19, 2025

I should have looked at the CI before I looked at the code 🤦‍♀️

@rcomer
Copy link
Member

rcomer commented Jul 19, 2025

This breaks scatter because its PathCollection's transform is the IdentityTransform and the data information goes via the offset transform.

@timhoffm
Copy link
Member Author

Good point! We must update if either the transform or the offset transform use data coordinates. -> Fixed.

... 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.
@timhoffm timhoffm added this to the v3.10.4 milestone Jul 24, 2025
@tacaswell tacaswell merged commit 55f7b10 into matplotlib:main Jul 24, 2025
40 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jul 24, 2025
@timhoffm timhoffm deleted the fix-autolim branch July 24, 2025 19:07
timhoffm pushed a commit that referenced this pull request Jul 25, 2025
….. autolim=True) (#30351)

Co-authored-by: Thomas A Caswell <tcaswell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: fill_between with get_xaxis_transform increases y-limits
3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/matplotlib/matplotlib/pull/30327

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy