FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[ENH]: generalize artists opting in-to auto limits · Issue #25139 · matplotlib/matplotlib · GitHub

Repository navigation

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

Open

Description

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

Activity

  1. added this to the v3.8.0 milestone on Feb 2, 2023
  2. jklymak commented on Feb 2, 2023

    Member

    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.

  3. tacaswell commented on Feb 2, 2023

    MemberAuthor

    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.

  4. anntzer commented on Feb 2, 2023

    Contributor

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

  5. tacaswell commented on Feb 2, 2023

    MemberAuthor

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

  6. removed this from the v3.8.0 milestone on Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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


      Back | FazBrowse Home | New Git URL