X Tutup
Skip to content
Merged
20 changes: 20 additions & 0 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -903,6 +904,14 @@ def get_in_layout(self):
"""
return self._in_layout

def _get_in_autoscale(self):
"""
Return whether the artist is included in autoscaling calculations.

E.g. `.axes.Axes.autoscale_view()`.
"""
return self._in_autoscale

def _fully_clipped_to_axes(self):
"""
Return a boolean flag, ``True`` if the artist is clipped to the Axes
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Member

@timhoffm timhoffm Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be checked: Do we need to set the self._stale flag?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2409,6 +2409,7 @@ 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):
Expand All @@ -2430,6 +2431,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):
Expand Down Expand Up @@ -2502,6 +2504,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):
Expand Down Expand Up @@ -2599,6 +2602,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):
Expand Down
Loading
X Tutup