Skip to content

Commit 7247fa5

Browse files
committed
Make autoscale participation fully artist-driven and Remove scatter relim regression test (to be added in follow-up PR)
1 parent 5bf5273 commit 7247fa5

3 files changed

Lines changed: 15 additions & 37 deletions

File tree

lib/matplotlib/artist.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +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 = True
228+
self._in_autoscale = False
229229

230230
def __getstate__(self):
231231
d = self.__dict__.copy()
@@ -904,16 +904,14 @@ def get_in_layout(self):
904904
"""
905905
return self._in_layout
906906

907-
def get_in_autoscale(self):
907+
def _get_in_autoscale(self):
908908
"""
909909
Return boolean flag, ``True`` if artist is included in autoscaling
910910
calculations.
911911
912-
E.g. :ref:`autoscaling_guide` and
913-
`.Axes.relim()`.
912+
E.g. `.axes.Axes.autoscale_view()`.
914913
"""
915-
return self._in_autoscale
916-
914+
return self._in_autoscale
917915
def _fully_clipped_to_axes(self):
918916
"""
919917
Return a boolean flag, ``True`` if the artist is clipped to the Axes
@@ -1143,17 +1141,16 @@ def set_in_layout(self, in_layout):
11431141
"""
11441142
self._in_layout = in_layout
11451143

1146-
def set_in_autoscale(self, in_autoscale):
1144+
def _set_in_autoscale(self, b):
11471145
"""
11481146
Set if artist is to be included in autoscaling calculations,
1149-
E.g. :ref:`autoscaling_guide` and
1150-
`.Axes.relim()`.
1147+
E.g. `.axes.Axes.autoscale_view()`.
11511148
11521149
Parameters
11531150
----------
1154-
in_autoscale : bool
1151+
b : bool
11551152
"""
1156-
self._in_autoscale = in_autoscale
1153+
self._in_autoscale = b
11571154

11581155
def get_label(self):
11591156
"""Return the label used for this artist in the legend."""

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,7 @@ def add_artist(self, a):
23172317
if a.get_clip_path() is None:
23182318
a.set_clip_path(self.patch)
23192319
self.stale = True
2320+
a._set_in_autoscale(False)
23202321
return a
23212322

23222323
def add_child_axes(self, ax):
@@ -2397,6 +2398,7 @@ def add_collection(self, collection, autolim=True):
23972398
self._request_autoscale_view()
23982399

23992400
self.stale = True
2401+
collection._set_in_autoscale(autolim)
24002402
return collection
24012403

24022404
def add_image(self, image):
@@ -2410,6 +2412,7 @@ def add_image(self, image):
24102412
self._children.append(image)
24112413
image._remove_method = self._children.remove
24122414
self.stale = True
2415+
image._set_in_autoscale(True)
24132416
return image
24142417

24152418
def _update_image_limits(self, image):
@@ -2437,6 +2440,7 @@ def add_line(self, line):
24372440
self._children.append(line)
24382441
line._remove_method = self._children.remove
24392442
self.stale = True
2443+
line._set_in_autoscale(True)
24402444
return line
24412445

24422446
def _add_text(self, txt):
@@ -2509,6 +2513,7 @@ def add_patch(self, p):
25092513
self._update_patch_limits(p)
25102514
self._children.append(p)
25112515
p._remove_method = self._children.remove
2516+
p._set_in_autoscale(True)
25122517
return p
25132518

25142519
def _update_patch_limits(self, patch):
@@ -2606,7 +2611,7 @@ def relim(self, visible_only=False):
26062611

26072612
for artist in self._children:
26082613
if not visible_only or artist.get_visible():
2609-
if not artist.get_in_autoscale():
2614+
if not artist._get_in_autoscale():
26102615
continue
26112616
if isinstance(artist, mlines.Line2D):
26122617
self._update_line_limits(artist)

lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10158,28 +10158,4 @@ def test_animated_artists_not_drawn_by_default():
1015810158
fig.draw_without_rendering()
1015910159

1016010160
mocked_im_draw.assert_not_called()
10161-
mocked_ln_draw.assert_not_called()
10162-
10163-
10164-
def test_relim_updates_scatter_offsets():
10165-
import numpy as np
10166-
import matplotlib.pyplot as plt
10167-
10168-
fig, ax = plt.subplots()
10169-
10170-
xs = np.linspace(0, 10, 100)
10171-
ys = np.sin(xs)
10172-
scatter = ax.scatter(xs, ys)
10173-
10174-
# Shift scatter upward
10175-
new_ys = np.sin(xs) + 5
10176-
scatter.set_offsets(np.column_stack((xs, new_ys)))
10177-
10178-
ax.relim()
10179-
ax.autoscale_view()
10180-
10181-
ymin, ymax = ax.get_ylim()
10182-
10183-
# New limits should reflect shifted data
10184-
assert ymin > 3
10185-
assert ymax > 5
10161+
mocked_ln_draw.assert_not_called()

0 commit comments

Comments
 (0)