8000 Inline ContourSet._make_paths. · matplotlib/matplotlib@5178736 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5178736

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 5178736

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

lib/matplotlib/contour.py

Lines changed: 18 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,17 @@ 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 corresponding pathcodes.
833+
# However, kinds can also be None; in which case all paths in that list
834+
# are codeless.
835+
allpaths = [
836+
[*map(mpath.Path,
837+
segs,
838+
kinds if kinds is not None else itertools.repeat(None))]
839+
for segs, kinds in zip(self.allsegs, self.allkinds)]
840+
829841
if self.filled:
830842
if self.linewidths is not None:
831843
_api.warn_external('linewidths is ignored by contourf')
@@ -836,14 +848,14 @@ def __init__(self, ax, *args,
836848

837849
self.collections[:] = [
838850
mcoll.PathCollection(
839-
self._make_paths(segs, kinds),
851+
paths,
840852
antialiaseds=(self.antialiased,),
841853
edgecolors='none',
842854
alpha=self.alpha,
843855
transform=self.get_transform(),
844856
zorder=self._contour_zorder)
845-
for level, level_upper, segs, kinds
846-
in zip(lowers, uppers, self.allsegs, self.allkinds)]
857+
for level, level_upper, paths
858+
in zip(lowers, uppers, allpaths)]
847859
else:
848860
self.tlinewidths = tlinewidths = self._process_linewidths()
849861
tlinestyles = self._process_linestyles()
@@ -856,7 +868,7 @@ def __init__(self, ax, *args,
856868

857869
self.collections[:] = [
858870
mcoll.PathCollection(
859-
self._make_paths(segs, kinds),
871+
paths,
860872
facecolors="none",
861873
antialiaseds=aa,
862874
linewidths=width,
@@ -865,9 +877,8 @@ def __init__(self, ax, *args,
865877
transform=self.get_transform(),
866878
zorder=self._contour_zorder,
867879
label='_nolegend_')
868-
for level, width, lstyle, segs, kinds
869-
in zip(self.levels, tlinewidths, tlinestyles, self.allsegs,
870-
self.allkinds)]
880+
for level, width, lstyle, paths
881+
in zip(self.levels, tlinewidths, tlinestyles, allpaths)]
871882

872883
for col in self.collections:
873884
self.axes.add_collection(col, autolim=False)
@@ -1029,23 +1040,6 @@ def _get_lowers_and_uppers(self):
10291040
uppers = self._levels[1:]
10301041
return (lowers, uppers)
10311042

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-
10491043
def changed(self):
10501044
if not hasattr(self, "cvalues"):
10511045
# Just return after calling the super() changed function

0 commit comments

Comments
 (0)
0