3
3
"""
4
4
5
5
import functools
6
+ import itertools
6
7
from numbers import Integral
7
8
8
9
import numpy as np
@@ -826,6 +827,17 @@ def __init__(self, ax, *args,
826
827
# well. Must ensure allkinds can be zipped below.
827
828
self .allkinds = [None ] * len (self .allsegs )
828
829
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
+
829
841
if self .filled :
830
842
if self .linewidths is not None :
831
843
_api .warn_external ('linewidths is ignored by contourf' )
@@ -836,14 +848,14 @@ def __init__(self, ax, *args,
836
848
837
849
self .collections [:] = [
838
850
mcoll .PathCollection (
839
- self . _make_paths ( segs , kinds ) ,
851
+ paths ,
840
852
antialiaseds = (self .antialiased ,),
841
853
edgecolors = 'none' ,
842
854
alpha = self .alpha ,
843
855
transform = self .get_transform (),
844
856
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 )]
847
859
else :
848
860
self .tlinewidths = tlinewidths = self ._process_linewidths ()
849
861
tlinestyles = self ._process_linestyles ()
@@ -856,7 +868,7 @@ def __init__(self, ax, *args,
856
868
857
869
self .collections [:] = [
858
870
mcoll .PathCollection (
859
- self . _make_paths ( segs , kinds ) ,
871
+ paths ,
860
872
facecolors = "none" ,
861
873
antialiaseds = aa ,
862
874
linewidths = width ,
@@ -865,9 +877,8 @@ def __init__(self, ax, *args,
865
877
transform = self .get_transform (),
866
878
zorder = self ._contour_zorder ,
867
879
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 )]
871
882
872
883
for col in self .collections :
873
884
self .axes .add_collection (col , autolim = False )
@@ -1029,23 +1040,6 @@ def _get_lowers_and_uppers(self):
1029
1040
uppers = self ._levels [1 :]
1030
1041
return (lowers , uppers )
1031
1042
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
-
1049
1043
def changed (self ):
1050
1044
if not hasattr (self , "cvalues" ):
1051
1045
# Just return after calling the super() changed function
0 commit comments