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