Skip to content
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

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

Open
tacaswell opened this issue Feb 2, 2023 · 4 comments
Open

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

tacaswell opened this issue Feb 2, 2023 · 4 comments
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues New feature

Comments

@tacaswell
Copy link
Member

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

@tacaswell tacaswell added New feature Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels Feb 2, 2023
@tacaswell tacaswell added this to the v3.8.0 milestone Feb 2, 2023
@jklymak
Copy link
Member

jklymak commented Feb 2, 2023

A major difficulty is that many of our Artists may be anchored in data co-ordinates, but their bounding boxes are not in data-coordinates.

@tacaswell
Copy link
Member Author

True, but now we can stuff that complexity back to the Artist classes where we have the best chance of knowing how to actually resolve that problem.

@anntzer
Copy link
Contributor

anntzer commented Feb 2, 2023

See #15595, which I had tried to push for during a sprint.

@tacaswell
Copy link
Member Author

oh, nice that even has some good discussion over the tricky parts of the API (that I participated in and have no memory of 😞 )!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues New feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants