Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 638f551

Browse files
robmarkcoletacaswell
authored andcommitted
Working test for line
1 parent 38abc71 commit 638f551

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

lib/matplotlib/artist.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def __init__(self):
212212
self._path_effects = mpl.rcParams['path.effects']
213213
self._sticky_edges = _XYPair([], [])
214214
self._in_layout = True
215+
self._in_autoscale = True
215216

216217
def __getstate__(self):
217218
d = self.__dict__.copy()
@@ -887,6 +888,13 @@ def _fully_clipped_to_axes(self):
887888
or isinstance(clip_path, TransformedPatchPath)
888889
and clip_path._patch is self.axes.patch))
889890

891+
def get_in_autoscale(self):
892+
"""
893+
Return boolean flag, ``True`` if artist is included in autoscale
894+
calculations.
895+
"""
896+
return self._in_autoscale
897+
890898
def get_clip_on(self):
891899
"""Return whether the artist uses clipping."""
892900
return self._clipon
@@ -1090,6 +1098,16 @@ def set_in_layout(self, in_layout):
10901098
"""
10911099
self._in_layout = in_layout
10921100

1101+
def set_in_autoscale(self, in_autoscale):
1102+
"""
1103+
Set if artist is to be included in autoscale calculations.
1104+
1105+
Parameters
1106+
----------
1107+
in_autoscale : bool
1108+
"""
1109+
self._in_autoscale = in_autoscale
1110+
10931111
def get_label(self):
10941112
"""Return the label used for this artist in the legend."""
10951113
return self._label

lib/matplotlib/axes/_base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,8 @@ def add_image(self, image):
22892289
return image
22902290

22912291
def _update_image_limits(self, image):
2292+
if not image.get_in_autoscale():
2293+
return
22922294
xmin, xmax, ymin, ymax = image.get_extent()
22932295
self.axes.update_datalim(((xmin, ymin), (xmax, ymax)))
22942296

@@ -2324,6 +2326,9 @@ def _update_line_limits(self, line):
23242326
"""
23252327
Figures out the data limit of the given line, updating self.dataLim.
23262328
"""
2329+
if not line.get_in_autoscale():
2330+
return
2331+
23272332
path = line.get_path()
23282333
if path.vertices.size == 0:
23292334
return
@@ -2391,6 +2396,9 @@ def _update_patch_limits(self, patch):
23912396
# cannot check for '==0' since unitized data may not compare to zero
23922397
# issue #2150 - we update the limits if patch has non zero width
23932398
# or height.
2399+
if not patch.get_in_autoscale():
2400+
return
2401+
23942402
if (isinstance(patch, mpatches.Rectangle) and
23952403
((not patch.get_width()) and (not patch.get_height()))):
23962404
return

lib/matplotlib/tests/test_artist.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,23 @@ def draw(self, renderer, extra):
562562

563563
assert 'aardvark' == art.draw(renderer, 'aardvark')
564564
assert 'aardvark' == art.draw(renderer, extra='aardvark')
565+
566+
567+
def test_in_autoscale_true():
568+
# test autoscale is performed when in_autoscale=True.
569+
fig, ax = plt.subplots()
570+
ax.plot([0, 1])
571+
ax.plot([0, 1, 2, 3], in_autoscale=True)
572+
ax.margins(0)
573+
ax.autoscale_view()
574+
assert ax.get_xlim() == ax.get_ylim() == (0, 3)
575+
576+
577+
def test_in_autoscale_false():
578+
# test autoscale is not performed when in_autoscale=False.
579+
fig, ax = plt.subplots()
580+
ax.plot([0, 1])
581+
ax.plot([0, 1, 2, 3], in_autoscale=False)
582+
ax.margins(0)
583+
ax.autoscale_view()
584+
assert ax.get_xlim() == ax.get_ylim() == (0, 1) # The default limits.

0 commit comments

Comments
 (0)