@@ -553,45 +553,6 @@ def _contour_args(self, filled, origin, extent, *args):
553553 self .ax .set_ylim ((ma .minimum (y ), ma .maximum (y )))
554554 return (x , y , z , lev )
555555
556-
557- def _initialize_reg_tri (self , z ):
558- '''
559- Initialize two arrays used by the low-level contour
560- algorithm. This is temporary code; most of the reg
561- initialization should be done in c.
562-
563- For each masked point, we need to mark as missing
564- the four regions with that point as a corner.
565- '''
566- imax , jmax = shape (z )
567- nreg = jmax * (imax + 1 )+ 1
568- reg = ones ((1 , nreg ), typecode = 'i' )
569- reg [0 ,:jmax + 1 ]= 0
570- reg [0 ,- jmax :]= 0
571- for j in range (0 , nreg , jmax ):
572- reg [0 ,j ]= 0
573- badmask = z .mask ()
574- if badmask is not None :
575- for i in range (imax ):
576- for j in range (jmax ):
577- if badmask [i ,j ]:
578- ii = i * jmax + j
579- if ii < nreg :
580- reg [0 ,ii ] = 0
581- ii += 1
582- if ii < nreg :
583- reg [0 ,ii ] = 0
584- ii += jmax
585- if ii < nreg :
586- reg [0 ,ii ] = 0
587- ii -= 1
588- if ii < nreg :
589- reg [0 ,ii ] = 0
590-
591- triangle = zeros ((imax ,jmax ), typecode = 's' )
592-
593- return reg , triangle
594-
595556 def _process_colors (self , z , colors , alpha , lev , cmap ):
596557 """
597558 Color argument processing for contouring.
@@ -728,8 +689,6 @@ def contour(self, *args, **kwargs):
728689 Ncolors = Nlev
729690
730691
731- reg , triangle = self ._initialize_reg_tri (z )
732-
733692 tcolors , mappable , collections = self ._process_colors (
734693 z , colors , alpha , lev , cmap )
735694
@@ -743,13 +702,9 @@ def contour(self, *args, **kwargs):
743702 tlinewidths = [(w ,) for w in linewidths ]
744703
745704 region = 0
705+ C = _contour .Cntr (x , y , z .filled (), z .mask ())
746706 for level , color , width in zip (lev , tcolors , tlinewidths ):
747- ntotal , nparts = _contour .GcInit1 (x , y , reg , triangle ,
748- region , z .filled (), level )
749- np = zeros ((nparts ,), typecode = 'l' )
750- xp = zeros ((ntotal , ), Float64 )
751- yp = zeros ((ntotal ,), Float64 )
752- nlist = _contour .GcTrace (np , xp , yp )
707+ nlist = C .trace (level , points = 1 )
753708 col = LineCollection (nlist )
754709 col .set_color (color )
755710 col .set_linewidth (width )
@@ -852,24 +807,16 @@ def contourf(self, *args, **kwargs):
852807
853808 Nlev = len (lev )
854809
855-
856- reg , triangle = self ._initialize_reg_tri (z )
857-
858810 tcolors , mappable , collections = self ._process_colors (z , colors ,
859811 alpha ,
860812 lev , cmap )
861813
862814 region = 0
863815 lev_upper = list (lev [1 :])
864816 lev_upper .append (1e38 )
817+ C = _contour .Cntr (x , y , z .filled (), z .mask ())
865818 for level , level_upper , color in zip (lev , lev_upper , tcolors ):
866- levs = (level , level_upper )
867- ntotal , nparts = _contour .GcInit2 (x , y , reg , triangle ,
868- region , z .filled (), levs , 30 )
869- np = zeros ((nparts ,), typecode = 'l' )
870- xp = zeros ((ntotal , ), Float64 )
871- yp = zeros ((ntotal ,), Float64 )
872- nlist = _contour .GcTrace (np , xp , yp )
819+ nlist = C .trace (level , level_upper , points = 1 )
873820 col = PolyCollection (nlist ,
874821 linewidths = (1 ,))
875822 # linewidths = 1 is necessary to avoid artifacts
0 commit comments