Add private Artist-level autoscale participation flag#31166
Add private Artist-level autoscale participation flag#31166ksunden merged 10 commits intomatplotlib:mainfrom
Conversation
|
Thanks for opening this PR! Could you give a bit more context to what future work this change will enable? |
|
See #31128 (comment) |
timhoffm
left a comment
There was a problem hiding this comment.
This is not yet appropriate
- the getter and setter must be private.
- the in autoscale logic is not implemented
- the artists need to be pre-defined with in autoscale in alignment with their current behavior
To be clear, this PR must provide the full in autoscale logic, shifting the in-behavior hard-coded logic to only depending on the artist property.
…elim regression test (to be added in follow-up PR)
|
The scatter relim regression test was removed from this PR since it exercises follow-up behavior (PR2). I’ll reintroduce it once PathCollection autoscaling is wired via the new artist flag. |
|
Thanks for the clarification — I’ve updated the PR so autoscale participation is fully artist-driven. The flag is now initialized in the add_* methods to preserve existing behavior, and relim() only gates on the artist property. |
|
@dstansby Thanks for the question! The goal of this change is to make inclusion in autoscaling an explicit, artist-level property, rather than relying on hard-coded type checks spread across Axes methods. In the short term, this PR does not change behavior; it only introduces the minimal infrastructure needed to express whether an artist participates in autoscaling in a uniform way. This enables follow-up work to: -Make add_collection(..., autolim=...) and similar APIs consistent across artist types. -Decouple autoscaling decisions from specific artist classes, allowing more predictable and testable behavior. -Incrementally refactor limit handling to query artists for their autoscale participation, instead of embedding logic in Axes.relim and related methods. -Concretely, this is intended to support the follow-up PRs discussed above, where conditional autoscaling of collections and a more unified limits architecture can be implemented without further ad-hoc checks. |
lib/matplotlib/axes/_base.py
Outdated
| if a.get_clip_path() is None: | ||
| a.set_clip_path(self.patch) | ||
| self.stale = True | ||
| a._set_in_autoscale(False) |
There was a problem hiding this comment.
Yes — the intent was to make the current behavior explicit.
add_artist historically does not opt the artist into autoscaling, so setting _in_autoscale(False) there makes that behavior explicit and avoids relying on defaults. This keeps relim() fully driven by the artist property rather than by implicit assumptions.
There was a problem hiding this comment.
I'd argue otherwise: For all standard cases this does nothing, because the default value is False. It would only have an effect a user would manually do artist.set_in_autoscale(True); ax.add_artist(artist). But we just have created set_in_autoscale() so that we don't have do consider backward compatibility in that case. And logically, overriding the in_autoscale settting through add_artist() would be surprising. So it's better to leave this out here and rely on the global default that an artist does not take part in autoscaling, unless we've explicitly opted in for that.
| ---------- | ||
| b : bool | ||
| """ | ||
| self._in_autoscale = b |
There was a problem hiding this comment.
To be checked: Do we need to set the self._stale flag?
There was a problem hiding this comment.
I don’t think _set_in_autoscale should mark the artist as stale.
The flag only affects whether the artist participates in future autoscaling; it doesn’t change the artist’s visual state or require a redraw on its own. In practice it’s set during add_*, before any drawing occurs, so marking it stale would be unnecessary.
There was a problem hiding this comment.
Ok, so the argument is that changing in_autoscale will not result in automatic recalculation of the limits. Accepted.
Can you please add a sentence on this to the docstring.
lib/matplotlib/axes/_base.py
Outdated
| self._request_autoscale_view() | ||
|
|
||
| self.stale = True | ||
| collection._set_in_autoscale(autolim) |
There was a problem hiding this comment.
For the scope of the PR, this does not have any effect as collections do not take part in limit calculation. So we could leave this out.
Note that currently the autolim parameter is a one-time action to update the data limits.
You may keep it in anticipation of the upcoming changes for #31128. But if you do, you should move it to before if autolim: and add a comment that this does not have any effect yet.
There was a problem hiding this comment.
Thanks for the clarification — that makes sense.
I’ll remove this for now and keep the PR focused on introducing the artist-level flag without anticipating collection behavior. We can wire this up properly once collections participate in limit calculation.
lib/matplotlib/axes/_base.py
Outdated
| def _update_collection_limits(self, collection): | ||
| offsets = collection.get_offsets() | ||
| if offsets is not None and len(offsets): | ||
| self.update_datalim(offsets) | ||
|
|
||
|
|
There was a problem hiding this comment.
Please remove. This is not within the scope of this PR but belongs in #31128.
There was a problem hiding this comment.
Sure — removed. I’ll keep collection limit handling for #31128 and keep this PR focused on introducing the artist-level autoscale flag only.
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
|
Thanks for the review and guidance! |
|
Yes, this should have been squashed-merged. :/ |
|
Thanks for the review and guidance throughout this PR. |
Introduce a private Artist-level
_in_autoscaleflag (mirroring_in_layout) and gate autoscaling centrally inAxes.relim().This PR is preparatory infrastructure only and does not intend to change existing behavior. Follow-up work will build on this to address collection.