88import numpy as np
99from numpy import ma
1010import matplotlib ._cntr as _cntr
11- import matplotlib .path as path
11+ import matplotlib .path as mpath
1212import matplotlib .ticker as ticker
1313import matplotlib .cm as cm
1414import matplotlib .colors as colors
@@ -499,7 +499,7 @@ def labels(self, inline, inline_spacing):
499499 if inline :
500500 for n in new :
501501 # Add path if not empty or single point
502- if len (n )> 1 : additions .append ( path .Path (n ) )
502+ if len (n )> 1 : additions .append ( mpath .Path (n ) )
503503 else : # If not adding label, keep old path
504504 additions .append (linepath )
505505
@@ -579,6 +579,8 @@ def __init__(self, ax, *args, **kwargs):
579579 self .collections = cbook .silent_list ('collections.PolyCollection' )
580580 else :
581581 self .collections = cbook .silent_list ('collections.LineCollection' )
582+ self .segs = []
583+ self .kinds = []
582584 # label lists must be initialized here
583585 self .labelTexts = []
584586 self .labelCValues = []
@@ -601,28 +603,41 @@ def __init__(self, ax, *args, **kwargs):
601603 for level , level_upper in zip (lowers , uppers ):
602604 nlist = C .trace (level , level_upper , points = 0 ,
603605 nchunk = self .nchunk )
604- col = collections .PolyCollection (nlist ,
606+ nseg = len (nlist )// 2
607+ segs = nlist [:nseg ]
608+ kinds = nlist [nseg :]
609+
610+
611+ paths = self ._make_paths (segs , kinds )
612+
613+ col = collections .PathCollection (paths ,
605614 antialiaseds = (self .antialiased ,),
606615 edgecolors = 'none' ,
607616 alpha = self .alpha )
608617 self .ax .add_collection (col )
609618 self .collections .append (col )
610-
619+ self .segs .append (segs )
620+ self .kinds .append (kinds )
611621 else :
612622 tlinewidths = self ._process_linewidths ()
613623 self .tlinewidths = tlinewidths
614624 tlinestyles = self ._process_linestyles ()
615625 C = _cntr .Cntr (x , y , z .filled (), _mask )
616626 for level , width , lstyle in zip (self .levels , tlinewidths , tlinestyles ):
617627 nlist = C .trace (level , points = 0 )
618- col = collections .LineCollection (nlist ,
628+ nseg = len (nlist )// 2
629+ segs = nlist [:nseg ]
630+ kinds = nlist [nseg :]
631+ col = collections .LineCollection (segs ,
619632 linewidths = width ,
620633 linestyle = lstyle ,
621634 alpha = self .alpha )
622635
623636 col .set_label ('_nolegend_' )
624637 self .ax .add_collection (col , False )
625638 self .collections .append (col )
639+ self .segs .append (segs )
640+ self .kinds .append (kinds )
626641 self .changed () # set the colors
627642 x0 = ma .minimum (x )
628643 x1 = ma .maximum (x )
@@ -631,6 +646,17 @@ def __init__(self, ax, *args, **kwargs):
631646 self .ax .update_datalim ([(x0 ,y0 ), (x1 ,y1 )])
632647 self .ax .autoscale_view ()
633648
649+ @staticmethod
650+ def _make_paths (segs , kinds ):
651+ paths = []
652+ for seg , kind in zip (segs , kinds ):
653+ codes = np .zeros (kind .shape , dtype = mpath .Path .code_type )
654+ codes .fill (mpath .Path .LINETO )
655+ codes [0 ] = mpath .Path .MOVETO
656+ codes [kinds >= _cntr ._slitkind ] = mpath .Path .MOVETO
657+ paths .append (mpath .Path (seg , codes ))
658+ return paths
659+
634660 def changed (self ):
635661 tcolors = [ (tuple (rgba ),) for rgba in
636662 self .to_rgba (self .cvalues , alpha = self .alpha )]
0 commit comments