X Tutup
Skip to content

Add private Artist-level autoscale participation flag#31166

Merged
ksunden merged 10 commits intomatplotlib:mainfrom
Archiljain:pr1-autoscale-flag
Mar 6, 2026
Merged

Add private Artist-level autoscale participation flag#31166
ksunden merged 10 commits intomatplotlib:mainfrom
Archiljain:pr1-autoscale-flag

Conversation

@Archiljain
Copy link
Contributor

Introduce a private Artist-level _in_autoscale flag (mirroring _in_layout) and gate autoscaling centrally in Axes.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.

@dstansby
Copy link
Member

Thanks for opening this PR! Could you give a bit more context to what future work this change will enable?

@timhoffm
Copy link
Member

See #31128 (comment)

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

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.

@Archiljain
Copy link
Contributor Author

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.

@Archiljain
Copy link
Contributor Author

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.

@Archiljain
Copy link
Contributor Author

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

if a.get_clip_path() is None:
a.set_clip_path(self.patch)
self.stale = True
a._set_in_autoscale(False)
Copy link
Member

@timhoffm timhoffm Feb 21, 2026

Choose a reason for hiding this comment

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

is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

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

@timhoffm timhoffm Feb 21, 2026

Choose a reason for hiding this comment

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

To be checked: Do we need to set the self._stale flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

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.

self._request_autoscale_view()

self.stale = True
collection._set_in_autoscale(autolim)
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +2421 to +2426
def _update_collection_limits(self, collection):
offsets = collection.get_offsets()
if offsets is not None and len(offsets):
self.update_datalim(offsets)


Copy link
Member

Choose a reason for hiding this comment

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

Please remove. This is not within the scope of this PR but belongs in #31128.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure — removed. I’ll keep collection limit handling for #31128 and keep this PR focused on introducing the artist-level autoscale flag only.

Archiljain and others added 4 commits February 26, 2026 18:14
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@Archiljain
Copy link
Contributor Author

Thanks for the review and guidance!
I’ll wait for this to be merged and then follow up with the next PR2 as discussed in #31128 .

@ksunden ksunden added this to the v3.11.0 milestone Mar 6, 2026
@ksunden ksunden merged commit 59ca203 into matplotlib:main Mar 6, 2026
41 checks passed
@QuLogic
Copy link
Member

QuLogic commented Mar 7, 2026

I suppose this should have been squash-merged, or at least rebased without extraneous changes, as #31128 has now been marked as merged even though all of those changes were reverted in follow-up commits in this PR, so #31128 is effectively not merged.

@timhoffm
Copy link
Member

timhoffm commented Mar 7, 2026

Yes, this should have been squashed-merged. :/

@Archiljain
Copy link
Contributor Author

Thanks for the review and guidance throughout this PR.
I’ll follow up with the next step discussed in #31128 building on this change.

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.

5 participants

X Tutup