@@ -127,7 +127,9 @@ def clabel(self, levels=None, *,
127
127
zorder : float or None, optional
128
128
zorder of the contour labels.
129
129
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.
131
133
132
134
Returns
133
135
-------
@@ -149,7 +151,14 @@ def clabel(self, levels=None, *,
149
151
# Detect if manual selection is desired and remove from argument list.
150
152
self .labelManual = manual
151
153
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
+
153
162
154
163
if levels is None :
155
164
levels = self .levels
@@ -403,7 +412,7 @@ def _get_label_text(self, x, y, rotation):
403
412
dx , dy = self .ax .transData .inverted ().transform ((x , y ))
404
413
t = text .Text (dx , dy , rotation = rotation ,
405
414
horizontalalignment = 'center' ,
406
- verticalalignment = 'center' , zorder = self ._zorder )
415
+ verticalalignment = 'center' , zorder = self ._clabel_zorder )
407
416
return t
408
417
409
418
def _get_label_clabeltext (self , x , y , rotation ):
@@ -417,7 +426,7 @@ def _get_label_clabeltext(self, x, y, rotation):
417
426
np .array ([[x , y ]]))
418
427
t = ClabelText (dx , dy , rotation = drotation [0 ],
419
428
horizontalalignment = 'center' ,
420
- verticalalignment = 'center' , zorder = self ._zorder )
429
+ verticalalignment = 'center' , zorder = self ._clabel_zorder )
421
430
422
431
return t
423
432
@@ -875,7 +884,7 @@ def __init__(self, ax, *args,
875
884
self .allkinds = [None ] * len (self .allsegs )
876
885
877
886
# Default zorder taken from Collection
878
- zorder = kwargs .pop ('zorder' , 1 )
887
+ self . _contour_zorder = kwargs .pop ('zorder' , 1 )
879
888
for level , level_upper , segs , kinds in \
880
889
zip (lowers , uppers , self .allsegs , self .allkinds ):
881
890
paths = self ._make_paths (segs , kinds )
@@ -886,7 +895,7 @@ def __init__(self, ax, *args,
886
895
edgecolors = 'none' ,
887
896
alpha = self .alpha ,
888
897
transform = self .get_transform (),
889
- zorder = zorder )
898
+ zorder = self . _contour_zorder )
890
899
self .ax .add_collection (col , autolim = False )
891
900
self .collections .append (col )
892
901
else :
@@ -897,7 +906,7 @@ def __init__(self, ax, *args,
897
906
if aa is not None :
898
907
aa = (self .antialiased ,)
899
908
# Default zorder taken from LineCollection
900
- zorder = kwargs .pop ('zorder' , 2 )
909
+ self . _contour_zorder = kwargs .pop ('zorder' , 2 )
901
910
for level , width , lstyle , segs in \
902
911
zip (self .levels , tlinewidths , tlinestyles , self .allsegs ):
903
912
col = mcoll .LineCollection (
@@ -907,7 +916,7 @@ def __init__(self, ax, *args,
907
916
linestyles = [lstyle ],
908
917
alpha = self .alpha ,
909
918
transform = self .get_transform (),
910
- zorder = zorder )
919
+ zorder = self . _contour_zorder )
911
920
col .set_label ('_nolegend_' )
912
921
self .ax .add_collection (col , autolim = False )
913
922
self .collections .append (col )
0 commit comments