-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Open
Labels
Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesNew feature
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
matplotlib/lib/matplotlib/axes/_base.py
Lines 2459 to 2483 in a046ee3
| 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) |
matplotlib/lib/matplotlib/axes/_base.py
Lines 2260 to 2273 in a046ee3
| 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_limitsand 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
relimlook 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).
timhoffm and alexiscoutinho
Metadata
Metadata
Assignees
Labels
Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesNew feature