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

Skip to content

Commit 7ea33dc

Browse files
committed
MNT: Use list comprehension
1 parent d2f87e8 commit 7ea33dc

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

lib/matplotlib/collections.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,12 +1232,8 @@ def set_verts_and_codes(self, verts, codes):
12321232
if len(verts) != len(codes):
12331233
raise ValueError("'codes' must be a 1D list or array "
12341234
"with the same length of 'verts'")
1235-
self._paths = []
1236-
for xy, cds in zip(verts, codes):
1237-
if len(xy):
1238-
self._paths.append(mpath.Path(xy, cds))
1239-
else:
1240-
self._paths.append(mpath.Path(xy))
1235+
self._paths = [mpath.Path(xy, cds) if len(xy) else mpath.Path(xy)
1236+
for xy, cds in zip(verts, codes)]
12411237
self.stale = True
12421238

12431239

@@ -1427,14 +1423,10 @@ def __init__(self, segments, # Can be None.
14271423
def set_segments(self, segments):
14281424
if segments is None:
14291425
return
1430-
_segments = []
1431-
1432-
for seg in segments:
1433-
if not isinstance(seg, np.ma.MaskedArray):
1434-
seg = np.asarray(seg, float)
1435-
_segments.append(seg)
14361426

1437-
self._paths = [mpath.Path(_seg) for _seg in _segments]
1427+
self._paths = [mpath.Path(seg) if isinstance(seg, np.ma.MaskedArray)
1428+
else mpath.Path(np.asarray(seg, float))
1429+
for seg in segments]
14381430
self.stale = True
14391431

14401432
set_verts = set_segments # for compatibility with PolyCollection

lib/matplotlib/contour.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,7 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
531531
paths.pop(segmin)
532532

533533
# Add paths if not empty or single point
534-
for n in nlc:
535-
if len(n) > 1:
536-
paths.append(mpath.Path(n))
534+
paths.extend([mpath.Path(n) for n in nlc if len(n) > 1])
537535

538536
def pop_label(self, index=-1):
539537
"""Defaults to removing last label, but any index can be supplied"""

lib/matplotlib/patches.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,11 +3165,9 @@ def __call__(self, path, mutation_size, linewidth,
31653165
mutation_size,
31663166
linewidth)
31673167
if np.iterable(fillable):
3168-
path_list = []
3169-
for p in path_mutated:
3170-
# Restore the height
3171-
path_list.append(
3172-
Path(p.vertices * [1, aspect_ratio], p.codes))
3168+
# Restore the height
3169+
path_list = [Path(p.vertices * [1, aspect_ratio], p.codes)
3170+
for p in path_mutated]
31733171
return path_list, fillable
31743172
else:
31753173
return path_mutated, fillable

0 commit comments

Comments
 (0)