Repository navigation
ENH: ax.add_collection(..., autolim=True) updates view limits - #29958
Merged
Merged
Conversation
timhoffm
marked this pull request as draft
April 22, 2025 09:59
timhoffm
force-pushed
the
add_collection_viewlims
branch
2 times, most recently
from
April 22, 2025 11:20
e5b0541 to
e7b2708
Compare
timhoffm
commented
Apr 22, 2025
| linewidths=[0.5 * mpl.rcParams['axes.linewidth']], | ||
| clip_on=False) | ||
| self.ax.add_collection(self.dividers) | ||
| self.ax.add_collection(self.dividers, autolim=False) |
Member
Author
There was a problem hiding this comment.
These are decorations on the colorbar and should not influence its limits.
timhoffm
commented
Apr 22, 2025
| col.set_clip_path(mpath.Path(xy, closed=True), | ||
| self.ax.transAxes) | ||
| self.ax.add_collection(col) | ||
| self.ax.add_collection(col, autolim=False) |
Member
Author
There was a problem hiding this comment.
Here as well: These are decorations on the colorbar and should not influence its limits.
timhoffm
commented
Apr 22, 2025
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) |
Member
Author
There was a problem hiding this comment.
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
marked this pull request as ready for review
April 22, 2025 11:44
scottshambaugh
approved these changes
May 6, 2025
dstansby
reviewed
May 18, 2025
timhoffm
force-pushed
the
add_collection_viewlims
branch
from
July 30, 2025 23:19
e7b2708 to
a080a71
Compare
QuLogic
reviewed
Aug 1, 2025
QuLogic
left a comment
Member
There was a problem hiding this comment.
There's one more call in galleries/examples/lines_bars_and_markers/multicolored_line.py that can probably be dropped?
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
force-pushed
the
add_collection_viewlims
branch
from
August 2, 2025 01:00
a080a71 to
5144212
Compare
QuLogic
approved these changes
Aug 2, 2025
5 tasks done
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.
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 ofadd_collection()andadd_collection3d(). This needs separate sorting . I've added a private valueautolim="_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:
autoscale_viewit may be that we can now remove the explicit limits for some cases since the autoscaled view is good enough.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 inmatplotlib/galleries/examples/shapes_and_collections/collections.py
Line 62 in 492a478
autolim=Falsemay have been the default a long time ago. - This should be investigated (Edit: Indeed, the default was changed in 2007 by 0df13d7).Closes #29957.