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

Skip to content

Commit 36d75b9

Browse files
Code comments
1 parent 02078f0 commit 36d75b9

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

lib/matplotlib/collections.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,13 +1511,13 @@ def _make_verts(self, t, f1, f2, where):
15111511
t, f1, f2 = np.broadcast_arrays(np.atleast_1d(t), f1, f2, subok=True)
15121512

15131513
self._bbox = transforms.Bbox.null()
1514-
t_w = t.data[where] if np.ma.isMA(t) else t[where]
1515-
n = len(t_w)
1514+
t_where = t.data[where] if np.ma.isMA(t) else t[where]
1515+
n = len(t_where)
15161516
if n > 0:
1517-
pts = np.empty((2 * n, 2))
1518-
pts[:n, 0] = t_w
1517+
pts = np.empty((2 * n, 2)) # Preallocate and fill for speed
1518+
pts[:n, 0] = t_where
15191519
pts[:n, 1] = f1.data[where] if np.ma.isMA(f1) else f1[where]
1520-
pts[n:, 0] = t_w
1520+
pts[n:, 0] = t_where
15211521
pts[n:, 1] = f2.data[where] if np.ma.isMA(f2) else f2[where]
15221522
self._bbox.update_from_data_xy(self._fix_pts_xy_order(pts))
15231523

lib/matplotlib/lines.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ def recache(self, always=False):
714714
vertices = self._xy
715715
else:
716716
steps = step_func(*self._xy.T)
717+
# Preallocate and fill for speed
717718
vertices = np.empty((steps.shape[1], 2))
718719
vertices[:, 0] = steps[0]
719720
vertices[:, 1] = steps[1]
@@ -735,6 +736,7 @@ def _transform_path(self, subslice=None):
735736
vertices = self._xy[subslice]
736737
else:
737738
steps = step_func(*self._xy[subslice, :].T)
739+
# Preallocate and fill for speed
738740
vertices = np.empty((steps.shape[1], 2))
739741
vertices[:, 0] = steps[0]
740742
vertices[:, 1] = steps[1]

lib/matplotlib/transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
909909
minx = np.min(x, initial=np.inf)
910910
points[0, 0] = min(points[0, 0], minx)
911911
points[1, 0] = max(points[1, 0], np.max(x, initial=-np.inf))
912-
if minx > 0:
912+
if minx > 0: # Fast path for all-positive x values
913913
minpos[0] = min(minpos[0], minx)
914914
else:
915915
minpos[0] = min(minpos[0], np.min(x[x > 0], initial=np.inf))
@@ -918,7 +918,7 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
918918
miny = np.min(y, initial=np.inf)
919919
points[0, 1] = min(points[0, 1], miny)
920920
points[1, 1] = max(points[1, 1], np.max(y, initial=-np.inf))
921-
if miny > 0:
921+
if miny > 0: # Fast path for all-positive y values
922922
minpos[1] = min(minpos[1], miny)
923923
else:
924924
minpos[1] = min(minpos[1], np.min(y[y > 0], initial=np.inf))

0 commit comments

Comments
 (0)