3
3
"""
4
4
5
5
import functools
6
- import itertools
7
6
from numbers import Integral
8
7
9
8
import numpy as np
@@ -767,6 +766,10 @@ def __init__(self, ax, *args,
767
766
self .negative_linestyles = \
768
767
mpl .rcParams ['contour.negative_linestyle' ]
769
768
769
+ # The base class _process_args will update _allpaths, which gets picked
770
+ # up by _get_allpaths below. OTOH the _process_args of subclasses
771
+ # leave _allpaths as None and instead set _contour_generator.
772
+ self ._allpaths = None
770
773
kwargs = self ._process_args (* args , ** kwargs )
771
774
self ._process_levels ()
772
775
@@ -820,23 +823,7 @@ def __init__(self, ax, *args,
820
823
self .norm .vmax = vmax
821
824
self ._process_colors ()
822
825
823
- if getattr (self , 'allsegs' , None ) is None :
824
- self .allsegs , self .allkinds = self ._get_allsegs_and_allkinds ()
825
- elif self .allkinds is None :
826
- # allsegs specified in constructor may or may not have allkinds as
827
- # well. Must ensure allkinds can be zipped below.
828
- self .allkinds = [None ] * len (self .allsegs )
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 )]
826
+ allpaths = self ._get_allpaths ()
840
827
841
828
if self .filled :
842
829
if self .linewidths is not None :
@@ -857,7 +844,7 @@ def __init__(self, ax, *args,
857
844
for level , level_upper , paths
858
845
in zip (lowers , uppers , allpaths )]
859
846
else :
860
- self . tlinewidths = tlinewidths = self ._process_linewidths ()
847
+ tlinewidths = self ._process_linewidths ()
861
848
tlinestyles = self ._process_linestyles ()
862
849
aa = self .antialiased
863
850
if aa is not None :
@@ -895,6 +882,15 @@ def __init__(self, ax, *args,
895
882
", " .join (map (repr , kwargs ))
896
883
)
897
884
885
+ allsegs = _api .deprecated ("3.8" , pending = True )(property (lambda self : [
886
+ p .vertices for c in self .collections for p in c .get_paths ()]))
887
+ allkinds = _api .deprecated ("3.8" , pending = True )(property (lambda self : [
888
+ p .codes for c in self .collections for p in c .get_paths ()]))
889
+ tcolors = _api .deprecated ("3.8" )(property (lambda self : [
890
+ (tuple (rgba ),) for rgba in self .to_rgba (self .cvalues , self .alpha )]))
891
+ tlinewidths = _api .deprecated ("3.8" )(
892
+ property (lambda self : self ._process_linewidths ()))
893
+
898
894
def get_transform (self ):
899
895
"""Return the `.Transform` instance used by this ContourSet."""
900
896
if self ._transform is None :
@@ -979,51 +975,60 @@ def _process_args(self, *args, **kwargs):
979
975
Must set self.levels, self.zmin and self.zmax, and update axes limits.
980
976
"""
981
977
self .levels = args [0 ]
982
- self . allsegs = args [1 ]
983
- self . allkinds = args [2 ] if len (args ) > 2 else None
978
+ allsegs = args [1 ]
979
+ allkinds = args [2 ] if len (args ) > 2 else None
984
980
self .zmax = np .max (self .levels )
985
981
self .zmin = np .min (self .levels )
986
982
983
+ if allkinds is None :
984
+ allkinds = [[None ] * len (segs ) for segs in allsegs ]
985
+
987
986
# Check lengths of levels and allsegs.
988
987
if self .filled :
989
- if len (self . allsegs ) != len (self .levels ) - 1 :
988
+ if len (allsegs ) != len (self .levels ) - 1 :
990
989
raise ValueError ('must be one less number of segments as '
991
990
'levels' )
992
991
else :
993
- if len (self . allsegs ) != len (self .levels ):
992
+ if len (allsegs ) != len (self .levels ):
994
993
raise ValueError ('must be same number of segments as levels' )
995
994
996
995
# Check length of allkinds.
997
- if (self .allkinds is not None and
998
- len (self .allkinds ) != len (self .allsegs )):
996
+ if len (allkinds ) != len (allsegs ):
999
997
raise ValueError ('allkinds has different length to allsegs' )
1000
998
1001
999
# Determine x, y bounds and update axes data limits.
1002
- flatseglist = [s for seg in self . allsegs for s in seg ]
1000
+ flatseglist = [s for seg in allsegs for s in seg ]
1003
1001
points = np .concatenate (flatseglist , axis = 0 )
1004
1002
self ._mins = points .min (axis = 0 )
1005
1003
self ._maxs = points .max (axis = 0 )
1006
1004
1005
+ # Each entry in (allsegs, allkinds) is a list of (segs, kinds) which
1006
+ # specifies a list of Paths: segs is a list of (N, 2) arrays of xy
1007
+ # coordinates, kinds is a list of arrays of corresponding pathcodes.
1008
+ # However, kinds can also be None; in which case all paths in that list
1009
+ # are codeless (this case is normalized above).
1010
+ self ._allpaths = [[* map (mpath .Path , segs , kinds )]
1011
+ for segs , kinds in zip (allsegs , allkinds )]
1012
+
1007
1013
return kwargs
1008
1014
1009
- def _get_allsegs_and_allkinds (self ):
1010
- """Compute ``allsegs`` and ``allkinds`` using C extension."""
1011
- allsegs = []
1012
- allkinds = []
1015
+ def _get_allpaths (self ):
1016
+ """Compute ``allpaths`` using C extension."""
1017
+ if self ._allpaths is not None :
1018
+ return self ._allpaths
1019
+ allpaths = []
1013
1020
if self .filled :
1014
1021
lowers , uppers = self ._get_lowers_and_uppers ()
1015
1022
for level , level_upper in zip (lowers , uppers ):
1016
1023
vertices , kinds = \
1017
1024
self ._contour_generator .create_filled_contour (
1018
1025
level , level_upper )
1019
- allsegs .append (vertices )
1020
- allkinds .append (kinds )
1026
+ allpaths .append ([* map (mpath .Path , vertices , kinds )])
1021
1027
else :
1022
1028
for level in self .levels :
1023
1029
vertices , kinds = self ._contour_generator .create_contour (level )
1024
- allsegs .append (vertices )
1025
- allkinds .append (kinds )
1026
- return allsegs , allkinds
1030
+ allpaths .append ([* map (mpath .Path , vertices , kinds )])
1031
+ return allpaths
1027
1032
1028
1033
def _get_lowers_and_uppers (self ):
1029
1034
"""
@@ -1052,7 +1057,6 @@ def changed(self):
1052
1057
self .norm .autoscale_None (self .levels )
1053
1058
tcolors = [(tuple (rgba ),)
1054
1059
for rgba in self .to_rgba (self .cvalues , alpha = self .alpha )]
1055
- self .tcolors = tcolors
1056
1060
hatches = self .hatches * len (tcolors )
1057
1061
for color , hatch , collection in zip (tcolors , hatches ,
1058
1062
self .collections ):
0 commit comments