-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Add private Artist-level autoscale participation flag #31166
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
Changes from 6 commits
529d37c
defd13e
fbb623e
5bf5273
7247fa5
b527465
0ad2c0a
6c702b6
bcf2fc2
31f59f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,6 +225,7 @@ def __init__(self): | |
| self._path_effects = mpl.rcParams['path.effects'] | ||
| self._sticky_edges = _XYPair([], []) | ||
| self._in_layout = True | ||
| self._in_autoscale = False | ||
|
|
||
| def __getstate__(self): | ||
| d = self.__dict__.copy() | ||
|
|
@@ -903,6 +904,14 @@ def get_in_layout(self): | |
| """ | ||
| return self._in_layout | ||
|
|
||
| def _get_in_autoscale(self): | ||
| """ | ||
| Return boolean flag, ``True`` if artist is included in autoscaling | ||
| calculations. | ||
|
|
||
| E.g. `.axes.Axes.autoscale_view()`. | ||
| """ | ||
| return self._in_autoscale | ||
|
Archiljain marked this conversation as resolved.
|
||
| def _fully_clipped_to_axes(self): | ||
| """ | ||
| Return a boolean flag, ``True`` if the artist is clipped to the Axes | ||
|
|
@@ -1132,6 +1141,17 @@ def set_in_layout(self, in_layout): | |
| """ | ||
| self._in_layout = in_layout | ||
|
|
||
| def _set_in_autoscale(self, b): | ||
| """ | ||
| Set if artist is to be included in autoscaling calculations, | ||
| E.g. `.axes.Axes.autoscale_view()`. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| b : bool | ||
| """ | ||
| self._in_autoscale = b | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be checked: Do we need to set the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| def get_label(self): | ||
| """Return the label used for this artist in the legend.""" | ||
| return self._label | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2316,6 +2316,7 @@ def add_artist(self, a): | |
| if a.get_clip_path() is None: | ||
| a.set_clip_path(self.patch) | ||
| self.stale = True | ||
| a._set_in_autoscale(False) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this needed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| return a | ||
|
|
||
| def add_child_axes(self, ax): | ||
|
|
@@ -2396,6 +2397,7 @@ def add_collection(self, collection, autolim=True): | |
| self._request_autoscale_view() | ||
|
|
||
| self.stale = True | ||
| collection._set_in_autoscale(autolim) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 You may keep it in anticipation of the upcoming changes for #31128. But if you do, you should move it to before
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarification — that makes sense. |
||
| return collection | ||
|
|
||
| def add_image(self, image): | ||
|
|
@@ -2409,12 +2411,19 @@ def add_image(self, image): | |
| self._children.append(image) | ||
| image._remove_method = self._children.remove | ||
| self.stale = True | ||
| image._set_in_autoscale(True) | ||
| return image | ||
|
|
||
| def _update_image_limits(self, image): | ||
| xmin, xmax, ymin, ymax = image.get_extent() | ||
| self.axes.update_datalim(((xmin, ymin), (xmax, ymax))) | ||
|
|
||
| def _update_collection_limits(self, collection): | ||
| offsets = collection.get_offsets() | ||
| if offsets is not None and len(offsets): | ||
| self.update_datalim(offsets) | ||
|
|
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| def add_line(self, line): | ||
| """ | ||
| Add a `.Line2D` to the Axes; return the line. | ||
|
|
@@ -2430,6 +2439,7 @@ def add_line(self, line): | |
| self._children.append(line) | ||
| line._remove_method = self._children.remove | ||
| self.stale = True | ||
| line._set_in_autoscale(True) | ||
| return line | ||
|
|
||
| def _add_text(self, txt): | ||
|
|
@@ -2502,6 +2512,7 @@ def add_patch(self, p): | |
| self._update_patch_limits(p) | ||
| self._children.append(p) | ||
| p._remove_method = self._children.remove | ||
| p._set_in_autoscale(True) | ||
| return p | ||
|
|
||
| def _update_patch_limits(self, patch): | ||
|
|
@@ -2599,6 +2610,8 @@ def relim(self, visible_only=False): | |
|
|
||
| for artist in self._children: | ||
| if not visible_only or artist.get_visible(): | ||
| if not artist._get_in_autoscale(): | ||
| continue | ||
| if isinstance(artist, mlines.Line2D): | ||
| self._update_line_limits(artist) | ||
| elif isinstance(artist, mpatches.Patch): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.