Skip to content

ENH: ax.add_collection(..., autolim=True) updates view limits #29958

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Apr 22, 2025

This makes explicit calls to autoscale_view() or _request_autoscale_view() unnecessary.

3D Axes have a special auto_scale_xyz(), also there's a mixture of add_collection() and add_collection3d(). This needs separate sorting . I've added a private value autolim="_datalim_only" to keep the behavior for 3D Axes unchanged for now. That will be resolved by a follow-up PR. I believe it's getting too complicated if we fold this into the 2D change.

Also for follow-ups:

  • There are some usages in tests and examples, where set_xlim/set_ylim pins the limits, which seems to be used as an alternative to autoscale_view it may be that we can now remove the explicit limits for some cases since the autoscaled view is good enough.
  • We have a number of places that explicitly use autolim=True, which is the default. We may remove these, but it seems they are sometimes used as explicit communication of intent. Also the comment in
    # explicitly, leave out the *autolim* keyword argument (or set it to False),
    suggests that autolim=False may have been the default a long time ago. - This should be investigated (Edit: Indeed, the default was changed in 2007 by 0df13d7).

Closes #29957.

This makes explicit calls to `autoscale_view()` or
`_request_autoscale_view()` unnecessary.

3D Axes have a special `auto_scale_xyz()`, also there's a mixture of
`add_collection()` and `add_collection3d()`. This needs separate sorting
. I've added a private value `autolim="_datalim_only"` to keep the
behavior for 3D Axes unchanged for now. That will be resolved by a
follow-up PR. I believe it's getting too complicated if we fold this
into the 2D change.
@timhoffm timhoffm force-pushed the add_collection_viewlims branch 2 times, most recently from e5b0541 to e7b2708 Compare April 22, 2025 11:20
@@ -371,7 +371,7 @@ def __init__(
colors=[mpl.rcParams['axes.edgecolor']],
linewidths=[0.5 * mpl.rcParams['axes.linewidth']],
clip_on=False)
self.ax.add_collection(self.dividers)
self.ax.add_collection(self.dividers, autolim=False)
Copy link
Member Author

Choose a reason for hiding this comment

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

These are decorations on the colorbar and should not influence its limits.

@@ -805,7 +805,7 @@ def add_lines(self, *args, **kwargs):
xy = self.ax.transAxes.inverted().transform(inches.transform(xy))
col.set_clip_path(mpath.Path(xy, closed=True),
self.ax.transAxes)
self.ax.add_collection(col)
self.ax.add_collection(col, autolim=False)
Copy link
Member Author

Choose a reason for hiding this comment

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

Here as well: These are decorations on the colorbar and should not influence its limits.

Comment on lines +166 to +168
# TODO: check whether the above explicit limit handling can be
# replaced by autolim=True
ax.add_collection(collection, autolim=False)
Copy link
Member Author

Choose a reason for hiding this comment

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

Since there is an explicit update_datalim(); autoscale_view() above, autolim=True has no effect. Setting autolim=False for now to make that clear. We may whether the explicit handling can be removed in favor of autolim=True, but I'll leave that for later.

@timhoffm timhoffm marked this pull request as ready for review April 22, 2025 11:44
@timhoffm timhoffm added this to the v3.11.0 milestone Apr 22, 2025
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.

[ENH]: add_collection(..., autolim=True) should update view limits as well
3 participants