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

Skip to content

Commit cf60835

Browse files
authored
Merge pull request #27518 from oscargus/mo
Micro-optimizations related to list handling
2 parents fed37f6 + ca72ba0 commit cf60835

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,7 @@ def get_gridlines(self, which="major", axis="both"):
354354
locs.extend(self.axes.xaxis.major.locator())
355355
if which in ("both", "minor"):
356356
locs.extend(self.axes.xaxis.minor.locator())
357-
358-
for x in locs:
359-
gridlines.append([[x, x], [y1, y2]])
357+
gridlines.extend([[x, x], [y1, y2]] for x in locs)
360358

361359
if axis in ("both", "y"):
362360
x1, x2 = self.axes.get_xlim()
@@ -365,9 +363,7 @@ def get_gridlines(self, which="major", axis="both"):
365363
locs.extend(self.axes.yaxis.major.locator())
366364
if self.axes.yaxis._minor_tick_kw["gridOn"]:
367365
locs.extend(self.axes.yaxis.minor.locator())
368-
369-
for y in locs:
370-
gridlines.append([[x1, x2], [y, y]])
366+
gridlines.extend([[x1, x2], [y, y]] for y in locs)
371367

372368
return gridlines
373369

lib/mpl_toolkits/axisartist/grid_finder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ def _find_line_box_crossings(xys, bbox):
3434
umin, vmin = bbox.min[sl]
3535
umax, vmax = bbox.max[sl]
3636
for u0, inside in [(umin, us > umin), (umax, us < umax)]:
37-
crossings.append([])
37+
cross = []
3838
idxs, = (inside[:-1] ^ inside[1:]).nonzero()
3939
for idx in idxs:
4040
v = vs[idx] + (u0 - us[idx]) * dvs[idx] / dus[idx]
4141
if not vmin <= v <= vmax:
4242
continue
4343
crossing = (u0, v)[sl]
4444
theta = np.degrees(np.arctan2(*dxys[idx][::-1]))
45-
crossings[-1].append((crossing, theta))
45+
cross.append((crossing, theta))
46+
crossings.append(cross)
4647
return crossings
4748

4849

0 commit comments

Comments
 (0)