Skip to content

[ENH]: generalize artists opting in-to auto limits #25139

Open
@tacaswell

Description

@tacaswell

Problem

This is triggered by #25127 most recently, but this is a discussion we have had a couple of times.

The core of the problem is that users have different expectations about what things will automatically adjust the axes limits (or not) in autolim mode. Currently Lines, Patches and AxesImage obligatorily participate

def relim(self, visible_only=False):
"""
Recompute the data limits based on current artists.
At present, `.Collection` instances are not supported.
Parameters
----------
visible_only : bool, default: False
Whether to exclude invisible artists.
"""
# Collections are deliberately not supported (yet); see
# the TODO note in artists.py.
self.dataLim.ignore(True)
self.dataLim.set_points(mtransforms.Bbox.null().get_points())
self.ignore_existing_data_limits = True
for artist in self._children:
if not visible_only or artist.get_visible():
if isinstance(artist, mlines.Line2D):
self._update_line_limits(artist)
elif isinstance(artist, mpatches.Patch):
self._update_patch_limits(artist)
elif isinstance(artist, mimage.AxesImage):
self._update_image_limits(artist)
and collections may optionally participate, but only when they are added
if autolim:
# Make sure viewLim is not stale (mostly to match
# pre-lazy-autoscale behavior, which is not really better).
self._unstale_viewLim()
datalim = collection.get_datalim(self.transData)
points = datalim.get_points()
if not np.isinf(datalim.minpos).all():
# By definition, if minpos (minimum positive value) is set
# (i.e., non-inf), then min(points) <= minpos <= max(points),
# and minpos would be superfluous. However, we add minpos to
# the call so that self.dataLim will update its own minpos.
# This ensures that log scales see the correct minimum.
points = np.concatenate([points, [datalim.minpos]])
self.update_datalim(points)

Proposed solution

The proposed solution is to:

  • move the _update_line_limits and friends to the respective Artists
  • add an analogous method to the base Artist (probably defaulting to failure)
  • add a "I would like to particpate in autolimiting!" flag to base Artist
  • in relim look at the flag and call the newly generalized method above on any artists that opt-in

This will involved a little bit of public API (how to set the state to opt-in) and a bunch of private API (what should the signature of the method be).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesNew feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions