@@ -127,7 +127,9 @@ def clabel(self, levels=None, *,
127127 zorder : float or None, optional
128128 zorder of the contour labels.
129129
130- If not specified, the default zorder of `.Text` class is used.
130+ If not specified, the zorder of contour labels is set to either
131+ (2 + zorder of contours) or (1 + zorder of contours) depending on
132+ whether the contours are filled or not filled.
131133
132134 Returns
133135 -------
@@ -149,7 +151,14 @@ def clabel(self, levels=None, *,
149151 # Detect if manual selection is desired and remove from argument list.
150152 self .labelManual = manual
151153 self .rightside_up = rightside_up
152- self ._zorder = zorder
154+ if zorder is None :
155+ if self .filled :
156+ self ._clabel_zorder = 2 + self ._contour_zorder
157+ else :
158+ self ._clabel_zorder = 1 + self ._contour_zorder
159+ else :
160+ self ._clabel_zorder = zorder
161+
153162
154163 if levels is None :
155164 levels = self .levels
@@ -403,7 +412,7 @@ def _get_label_text(self, x, y, rotation):
403412 dx , dy = self .ax .transData .inverted ().transform ((x , y ))
404413 t = text .Text (dx , dy , rotation = rotation ,
405414 horizontalalignment = 'center' ,
406- verticalalignment = 'center' , zorder = self ._zorder )
415+ verticalalignment = 'center' , zorder = self ._clabel_zorder )
407416 return t
408417
409418 def _get_label_clabeltext (self , x , y , rotation ):
@@ -417,7 +426,7 @@ def _get_label_clabeltext(self, x, y, rotation):
417426 np .array ([[x , y ]]))
418427 t = ClabelText (dx , dy , rotation = drotation [0 ],
419428 horizontalalignment = 'center' ,
420- verticalalignment = 'center' , zorder = self ._zorder )
429+ verticalalignment = 'center' , zorder = self ._clabel_zorder )
421430
422431 return t
423432
@@ -875,7 +884,7 @@ def __init__(self, ax, *args,
875884 self .allkinds = [None ] * len (self .allsegs )
876885
877886 # Default zorder taken from Collection
878- zorder = kwargs .pop ('zorder' , 1 )
887+ self . _contour_zorder = kwargs .pop ('zorder' , 1 )
879888 for level , level_upper , segs , kinds in \
880889 zip (lowers , uppers , self .allsegs , self .allkinds ):
881890 paths = self ._make_paths (segs , kinds )
@@ -886,7 +895,7 @@ def __init__(self, ax, *args,
886895 edgecolors = 'none' ,
887896 alpha = self .alpha ,
888897 transform = self .get_transform (),
889- zorder = zorder )
898+ zorder = self . _contour_zorder )
890899 self .ax .add_collection (col , autolim = False )
891900 self .collections .append (col )
892901 else :
@@ -897,7 +906,7 @@ def __init__(self, ax, *args,
897906 if aa is not None :
898907 aa = (self .antialiased ,)
899908 # Default zorder taken from LineCollection
900- zorder = kwargs .pop ('zorder' , 2 )
909+ self . _contour_zorder = kwargs .pop ('zorder' , 2 )
901910 for level , width , lstyle , segs in \
902911 zip (self .levels , tlinewidths , tlinestyles , self .allsegs ):
903912 col = mcoll .LineCollection (
@@ -907,7 +916,7 @@ def __init__(self, ax, *args,
907916 linestyles = [lstyle ],
908917 alpha = self .alpha ,
909918 transform = self .get_transform (),
910- zorder = zorder )
919+ zorder = self . _contour_zorder )
911920 col .set_label ('_nolegend_' )
912921 self .ax .add_collection (col , autolim = False )
913922 self .collections .append (col )
0 commit comments