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

Skip to content

Commit ec042a9

Browse files
committed
Eliminate duplicate Path instantiation
svn path=/trunk/matplotlib/; revision=6017
1 parent 872af73 commit ec042a9

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,9 @@ def add_line(self, line):
12821282
line._remove_method = lambda h: self.lines.remove(h)
12831283

12841284
def _update_line_limits(self, line):
1285-
xydata = line.get_xydata()
1286-
self.update_datalim( xydata )
1285+
self.dataLim.update_from_path(line.get_path(),
1286+
self.ignore_existing_data_limits)
1287+
self.ignore_existing_data_limits = False
12871288

12881289
def add_patch(self, p):
12891290
"""
@@ -1307,12 +1308,11 @@ def _update_patch_limits(self, p):
13071308
# the auto-scaling
13081309
if isinstance(p, mpatches.Rectangle) and (p.get_width()==0. or p.get_height()==0.):
13091310
return
1310-
13111311
vertices = p.get_patch_transform().transform(p.get_path().vertices)
13121312
if p.get_data_transform() != self.transData:
13131313
transform = p.get_data_transform() + self.transData.inverted()
13141314
xys = transform.transform(vertices)
1315-
1315+
# Something is wrong--xys is never used.
13161316
self.update_datalim(vertices)
13171317

13181318
def add_table(self, tab):
@@ -1327,6 +1327,8 @@ def add_table(self, tab):
13271327

13281328
def relim(self):
13291329
'recompute the data limits based on current artists'
1330+
# Collections are deliberately not supported (yet); see
1331+
# the TODO note in artists.py.
13301332
self.dataLim.ignore(True)
13311333
self.ignore_existing_data_limits = True
13321334
for line in self.lines:

lib/matplotlib/transforms.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -786,12 +786,12 @@ def update_from_data(self, x, y, ignore=None):
786786
xy = np.hstack((x.reshape((len(x), 1)), y.reshape((len(y), 1))))
787787
return self.update_from_data_xy(xy, ignore)
788788

789-
def update_from_data_xy(self, xy, ignore=None):
789+
def update_from_path(self, path, ignore=None):
790790
"""
791791
Update the bounds of the :class:`Bbox` based on the passed in
792792
data.
793793
794-
xy: a numpy array of 2D points
794+
path: a Path instance
795795
796796
ignore:
797797
- when True, ignore the existing bounds of the Bbox.
@@ -801,20 +801,33 @@ def update_from_data_xy(self, xy, ignore=None):
801801
if ignore is None:
802802
ignore = self._ignore
803803

804-
if len(xy) == 0:
805-
return
806-
xym = ma.masked_invalid(xy) # maybe add copy=False
807-
if (xym.count(axis=1)!=2).all():
808-
return
809-
810804
points, minpos, changed = update_path_extents(
811-
Path(xym), None, self._points, self._minpos, ignore)
805+
path, None, self._points, self._minpos, ignore)
812806

813807
if changed:
814808
self._points = points
815809
self._minpos = minpos
816810
self.invalidate()
817811

812+
813+
def update_from_data_xy(self, xy, ignore=None):
814+
"""
815+
Update the bounds of the :class:`Bbox` based on the passed in
816+
data.
817+
818+
xy: a numpy array of 2D points
819+
820+
ignore:
821+
- when True, ignore the existing bounds of the Bbox.
822+
- when False, include the existing bounds of the Bbox.
823+
- when None, use the last value passed to :meth:`ignore`.
824+
"""
825+
if len(xy) == 0:
826+
return
827+
828+
path = Path(xy)
829+
self.update_from_path(path, ignore=ignore)
830+
818831
def _set_x0(self, val):
819832
self._points[0, 0] = val
820833
self.invalidate()

0 commit comments

Comments
 (0)