@@ -51,7 +51,7 @@ class ContourLabeler:
5151 def clabel (self , levels = None , * ,
5252 fontsize = None , inline = True , inline_spacing = 5 , fmt = '%1.3f' ,
5353 colors = None , use_clabeltext = False , manual = False ,
54- rightside_up = True ):
54+ rightside_up = True , zorder = None ):
5555 """
5656 Label a contour plot.
5757
@@ -124,6 +124,12 @@ def clabel(self, levels=None, *,
124124 of texts during the drawing time, therefore this can be used if
125125 aspect of the axes changes.
126126
127+ zorder : float or None, optional
128+ zorder of the contour labels.
129+
130+ If not specified, the zorder of contour labels is set to
131+ (2 + zorder of contours).
132+
127133 Returns
128134 -------
129135 labels
@@ -144,6 +150,10 @@ def clabel(self, levels=None, *,
144150 # Detect if manual selection is desired and remove from argument list.
145151 self .labelManual = manual
146152 self .rightside_up = rightside_up
153+ if zorder is None :
154+ self ._clabel_zorder = 2 + self ._contour_zorder
155+ else :
156+ self ._clabel_zorder = zorder
147157
148158 if levels is None :
149159 levels = self .levels
@@ -397,7 +407,7 @@ def _get_label_text(self, x, y, rotation):
397407 dx , dy = self .ax .transData .inverted ().transform ((x , y ))
398408 t = text .Text (dx , dy , rotation = rotation ,
399409 horizontalalignment = 'center' ,
400- verticalalignment = 'center' )
410+ verticalalignment = 'center' , zorder = self . _clabel_zorder )
401411 return t
402412
403413 def _get_label_clabeltext (self , x , y , rotation ):
@@ -411,7 +421,7 @@ def _get_label_clabeltext(self, x, y, rotation):
411421 np .array ([[x , y ]]))
412422 t = ClabelText (dx , dy , rotation = drotation [0 ],
413423 horizontalalignment = 'center' ,
414- verticalalignment = 'center' )
424+ verticalalignment = 'center' , zorder = self . _clabel_zorder )
415425
416426 return t
417427
@@ -869,7 +879,7 @@ def __init__(self, ax, *args,
869879 self .allkinds = [None ] * len (self .allsegs )
870880
871881 # Default zorder taken from Collection
872- zorder = kwargs .pop ('zorder' , 1 )
882+ self . _contour_zorder = kwargs .pop ('zorder' , 1 )
873883 for level , level_upper , segs , kinds in \
874884 zip (lowers , uppers , self .allsegs , self .allkinds ):
875885 paths = self ._make_paths (segs , kinds )
@@ -880,7 +890,7 @@ def __init__(self, ax, *args,
880890 edgecolors = 'none' ,
881891 alpha = self .alpha ,
882892 transform = self .get_transform (),
883- zorder = zorder )
893+ zorder = self . _contour_zorder )
884894 self .ax .add_collection (col , autolim = False )
885895 self .collections .append (col )
886896 else :
@@ -891,7 +901,7 @@ def __init__(self, ax, *args,
891901 if aa is not None :
892902 aa = (self .antialiased ,)
893903 # Default zorder taken from LineCollection
894- zorder = kwargs .pop ('zorder' , 2 )
904+ self . _contour_zorder = kwargs .pop ('zorder' , 2 )
895905 for level , width , lstyle , segs in \
896906 zip (self .levels , tlinewidths , tlinestyles , self .allsegs ):
897907 col = mcoll .LineCollection (
@@ -901,7 +911,7 @@ def __init__(self, ax, *args,
901911 linestyles = [lstyle ],
902912 alpha = self .alpha ,
903913 transform = self .get_transform (),
904- zorder = zorder )
914+ zorder = self . _contour_zorder )
905915 col .set_label ('_nolegend_' )
906916 self .ax .add_collection (col , autolim = False )
907917 self .collections .append (col )
0 commit comments