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

Skip to content

Commit 46c9ceb

Browse files
fill_between _make_verts speedup
Fix tests
1 parent 0ccb4b5 commit 46c9ceb

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

lib/matplotlib/collections.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,15 @@ 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-
self._bbox.update_from_data_xy(self._fix_pts_xy_order(np.concatenate([
1515-
np.stack((t[where], f[where]), axis=-1) for f in (f1, f2)])))
1514+
t_w = t.data[where] if np.ma.isMA(t) else t[where]
1515+
n = len(t_w)
1516+
if n > 0:
1517+
pts = np.empty((2 * n, 2))
1518+
pts[:n, 0] = t_w
1519+
pts[:n, 1] = f1.data[where] if np.ma.isMA(f1) else f1[where]
1520+
pts[n:, 0] = t_w
1521+
pts[n:, 1] = f2.data[where] if np.ma.isMA(f2) else f2[where]
1522+
self._bbox.update_from_data_xy(self._fix_pts_xy_order(pts))
15161523

15171524
return [
15181525
self._make_verts_for_region(t, f1, f2, idx0, idx1)
@@ -1571,11 +1578,15 @@ def _make_verts_for_region(self, t, f1, f2, idx0, idx1):
15711578
start = t_slice[0], f2_slice[0]
15721579
end = t_slice[-1], f2_slice[-1]
15731580

1574-
pts = np.concatenate((
1575-
np.asarray([start]),
1576-
np.stack((t_slice, f1_slice), axis=-1),
1577-
np.asarray([end]),
1578-
np.stack((t_slice, f2_slice), axis=-1)[::-1]))
1581+
# Preallocate and fill for speed
1582+
n = len(t_slice)
1583+
pts = np.empty((2 * n + 2, 2))
1584+
pts[0] = start
1585+
pts[1:n+1, 0] = t_slice
1586+
pts[1:n+1, 1] = f1_slice
1587+
pts[n+1] = end
1588+
pts[n+2:, 0] = t_slice[::-1]
1589+
pts[n+2:, 1] = f2_slice[::-1]
15791590

15801591
return self._fix_pts_xy_order(pts)
15811592

0 commit comments

Comments
 (0)