X Tutup
Skip to content

Commit 59ca203

Browse files
authored
Merge pull request #31166 from Archiljain/pr1-autoscale-flag
Add private Artist-level autoscale participation flag
2 parents 2fb7100 + 31f59f4 commit 59ca203

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/matplotlib/artist.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def __init__(self):
225225
self._path_effects = mpl.rcParams['path.effects']
226226
self._sticky_edges = _XYPair([], [])
227227
self._in_layout = True
228+
self._in_autoscale = False
228229

229230
def __getstate__(self):
230231
d = self.__dict__.copy()
@@ -916,6 +917,14 @@ def get_in_layout(self):
916917
"""
917918
return self._in_layout
918919

920+
def _get_in_autoscale(self):
921+
"""
922+
Return whether the artist is included in autoscaling calculations.
923+
924+
E.g. `.axes.Axes.autoscale_view()`.
925+
"""
926+
return self._in_autoscale
927+
919928
def _fully_clipped_to_axes(self):
920929
"""
921930
Return a boolean flag, ``True`` if the artist is clipped to the Axes
@@ -1145,6 +1154,17 @@ def set_in_layout(self, in_layout):
11451154
"""
11461155
self._in_layout = in_layout
11471156

1157+
def _set_in_autoscale(self, b):
1158+
"""
1159+
Set if artist is to be included in autoscaling calculations,
1160+
E.g. `.axes.Axes.autoscale_view()`.
1161+
1162+
Parameters
1163+
----------
1164+
b : bool
1165+
"""
1166+
self._in_autoscale = b
1167+
11481168
def get_label(self):
11491169
"""Return the label used for this artist in the legend."""
11501170
return self._label

lib/matplotlib/axes/_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,7 @@ def add_image(self, image):
24252425
self._children.append(image)
24262426
image._remove_method = self._children.remove
24272427
self.stale = True
2428+
image._set_in_autoscale(True)
24282429
return image
24292430

24302431
def _update_image_limits(self, image):
@@ -2446,6 +2447,7 @@ def add_line(self, line):
24462447
self._children.append(line)
24472448
line._remove_method = self._children.remove
24482449
self.stale = True
2450+
line._set_in_autoscale(True)
24492451
return line
24502452

24512453
def _add_text(self, txt):
@@ -2518,6 +2520,7 @@ def add_patch(self, p):
25182520
self._update_patch_limits(p)
25192521
self._children.append(p)
25202522
p._remove_method = self._children.remove
2523+
p._set_in_autoscale(True)
25212524
return p
25222525

25232526
def _update_patch_limits(self, patch):
@@ -2615,6 +2618,8 @@ def relim(self, visible_only=False):
26152618

26162619
for artist in self._children:
26172620
if not visible_only or artist.get_visible():
2621+
if not artist._get_in_autoscale():
2622+
continue
26182623
if isinstance(artist, mlines.Line2D):
26192624
self._update_line_limits(artist)
26202625
elif isinstance(artist, mpatches.Patch):

0 commit comments

Comments
 (0)
X Tutup