From 1e32084fccdd8e027790a5afe0680a87454f5f89 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 17 Oct 2018 11:47:17 +0200 Subject: [PATCH] Avoid quadratic behavior when accumulating stickies. When plotting 10000 lines, this gives a ~10% improvement in performance. --- lib/matplotlib/axes/_base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 4a3081ed7ec0..4fb2d2c989b3 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2405,12 +2405,12 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True): if self.use_sticky_edges and (self._xmargin or self._ymargin): stickies = [artist.sticky_edges for artist in self.get_children()] - x_stickies = sum([sticky.x for sticky in stickies], []) - y_stickies = sum([sticky.y for sticky in stickies], []) + x_stickies = np.array([x for sticky in stickies for x in sticky.x]) + y_stickies = np.array([y for sticky in stickies for y in sticky.y]) if self.get_xscale().lower() == 'log': - x_stickies = [xs for xs in x_stickies if xs > 0] + x_stickies = x_stickies[x_stickies > 0] if self.get_yscale().lower() == 'log': - y_stickies = [ys for ys in y_stickies if ys > 0] + y_stickies = y_stickies[y_stickies > 0] else: # Small optimization. x_stickies, y_stickies = [], []