@@ -845,10 +845,8 @@ def __init__(self, ax, *args,
845845 if extend_max :
846846 cmap .set_over (self .colors [- 1 ])
847847
848- if self .filled :
849- self .collections = cbook .silent_list ('mcoll.PathCollection' )
850- else :
851- self .collections = cbook .silent_list ('mcoll.LineCollection' )
848+ self .collections = cbook .silent_list (None )
849+
852850 # label lists must be initialized here
853851 self .labelTexts = []
854852 self .labelCValues = []
@@ -869,53 +867,48 @@ def __init__(self, ax, *args,
869867 if self .filled :
870868 if self .linewidths is not None :
871869 cbook ._warn_external ('linewidths is ignored by contourf' )
872-
873870 # Lower and upper contour levels.
874871 lowers , uppers = self ._get_lowers_and_uppers ()
875-
876872 # Ensure allkinds can be zipped below.
877873 if self .allkinds is None :
878874 self .allkinds = [None ] * len (self .allsegs )
879-
880875 # Default zorder taken from Collection
881876 self ._contour_zorder = kwargs .pop ('zorder' , 1 )
882- for level , level_upper , segs , kinds in \
883- zip (lowers , uppers , self .allsegs , self .allkinds ):
884- paths = self ._make_paths (segs , kinds )
885877
886- col = mcoll .PathCollection (
887- paths ,
878+ self .collections [:] = [
879+ mcoll .PathCollection (
880+ self ._make_paths (segs , kinds ),
888881 antialiaseds = (self .antialiased ,),
889882 edgecolors = 'none' ,
890883 alpha = self .alpha ,
891884 transform = self .get_transform (),
892885 zorder = self ._contour_zorder )
893- self . axes . add_collection ( col , autolim = False )
894- self .collections . append ( col )
886+ for level , level_upper , segs , kinds
887+ in zip ( lowers , uppers , self .allsegs , self . allkinds )]
895888 else :
896- tlinewidths = self ._process_linewidths ()
897- self .tlinewidths = tlinewidths
889+ self .tlinewidths = tlinewidths = self ._process_linewidths ()
898890 tlinestyles = self ._process_linestyles ()
899891 aa = self .antialiased
900892 if aa is not None :
901893 aa = (self .antialiased ,)
902894 # Default zorder taken from LineCollection
903895 self ._contour_zorder = kwargs .pop ('zorder' , 2 )
904- for level , width , lstyle , segs in \
905- zip ( self .levels , tlinewidths , tlinestyles , self . allsegs ):
906- col = mcoll .LineCollection (
896+
897+ self .collections [:] = [
898+ mcoll .LineCollection (
907899 segs ,
908900 antialiaseds = aa ,
909901 linewidths = width ,
910902 linestyles = [lstyle ],
911903 alpha = self .alpha ,
912904 transform = self .get_transform (),
913- zorder = self ._contour_zorder )
914- col . set_label ( '_nolegend_' )
915- self . axes . add_collection ( col , autolim = False )
916- self .collections . append ( col )
905+ zorder = self ._contour_zorder ,
906+ label = '_nolegend_' )
907+ for level , width , lstyle , segs
908+ in zip ( self .levels , tlinewidths , tlinestyles , self . allsegs )]
917909
918910 for col in self .collections :
911+ self .axes .add_collection (col , autolim = False )
919912 col .sticky_edges .x [:] = [self ._mins [0 ], self ._maxs [0 ]]
920913 col .sticky_edges .y [:] = [self ._mins [1 ], self ._maxs [1 ]]
921914 self .axes .update_datalim ([self ._mins , self ._maxs ])
0 commit comments