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

Skip to content

Commit 0377aa8

Browse files
committed
Inline ContourSet._make_paths.
The docstring for _make_paths is extremely lengthy for what is just a list of map()s and can be more easily explained in a comment.
1 parent 1ad6cbf commit 0377aa8

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

lib/matplotlib/contour.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import functools
6+
import itertools
67
from numbers import Integral
78

89
import numpy as np
@@ -826,6 +827,16 @@ def __init__(self, ax, *args,
826827
# well. Must ensure allkinds can be zipped below.
827828
self.allkinds = [None] * len(self.allsegs)
828829

830+
# Each entry in (allsegs, allkinds) is a list of (segs, kinds) which
831+
# specifies a list of Paths (segs is a list of (N, 2) arrays of xy
832+
# coordinates, kinds is a list of arrays of pathcodes). However, kinds
833+
# can be None too in which case all paths in that list are codeless.
834+
allpaths = [
835+
[*map(mpath.Path,
836+
segs,
837+
kinds if kinds is not None else itertools.repeat(None))]
838+
for segs, kinds in zip(self.allsegs, self.allkinds)]
839+
829840
if self.filled:
830841
if self.linewidths is not None:
831842
_api.warn_external('linewidths is ignored by contourf')
@@ -836,14 +847,14 @@ def __init__(self, ax, *args,
836847

837848
self.collections[:] = [
838849
mcoll.PathCollection(
839-
self._make_paths(segs, kinds),
850+
paths,
840851
antialiaseds=(self.antialiased,),
841852
edgecolors='none',
842853
alpha=self.alpha,
843854
transform=self.get_transform(),
844855
zorder=self._contour_zorder)
845-
for level, level_upper, segs, kinds
846-
in zip(lowers, uppers, self.allsegs, self.allkinds)]
856+
for level, level_upper, paths
857+
in zip(lowers, uppers, allpaths)]
847858
else:
848859
self.tlinewidths = tlinewidths = self._process_linewidths()
849860
tlinestyles = self._process_linestyles()
@@ -856,7 +867,7 @@ def __init__(self, ax, *args,
856867

857868
self.collections[:] = [
858869
mcoll.PathCollection(
859-
self._make_paths(segs, kinds),
870+
paths,
860871
facecolors="none",
861872
antialiaseds=aa,
862873
linewidths=width,
@@ -865,9 +876,8 @@ def __init__(self, ax, *args,
865876
transform=self.get_transform(),
866877
zorder=self._contour_zorder,
867878
label='_nolegend_')
868-
for level, width, lstyle, segs, kinds
869-
in zip(self.levels, tlinewidths, tlinestyles, self.allsegs,
870-
self.allkinds)]
879+
for level, width, lstyle, paths
880+
in zip(self.levels, tlinewidths, tlinestyles, allpaths)]
871881

872882
for col in self.collections:
873883
self.axes.add_collection(col, autolim=False)
@@ -1029,23 +1039,6 @@ def _get_lowers_and_uppers(self):
10291039
uppers = self._levels[1:]
10301040
return (lowers, uppers)
10311041

1032-
def _make_paths(self, segs, kinds):
1033-
"""
1034-
Create and return Path objects for the specified segments and optional
1035-
kind codes. *segs* is a list of numpy arrays, each array is either a
1036-
closed line loop or open line strip of 2D points with a shape of
1037-
(npoints, 2). *kinds* is either None or a list (with the same length
1038-
as *segs*) of numpy arrays, each array is of shape (npoints,) and
1039-
contains the kind codes for the corresponding line in *segs*. If
1040-
*kinds* is None then the Path constructor creates the kind codes
1041-
assuming that the line is an open strip.
1042-
"""
1043-
if kinds is None:
1044-
return [mpath.Path(seg) for seg in segs]
1045-
else:
1046-
return [mpath.Path(seg, codes=kind) for seg, kind
1047-
in zip(segs, kinds)]
1048-
10491042
def changed(self):
10501043
if not hasattr(self, "cvalues"):
10511044
# Just return after calling the super() changed function

0 commit comments

Comments
 (0)