@@ -51,7 +51,7 @@ class ContourLabeler:
51
51
def clabel (self , levels = None , * ,
52
52
fontsize = None , inline = True , inline_spacing = 5 , fmt = '%1.3f' ,
53
53
colors = None , use_clabeltext = False , manual = False ,
54
- rightside_up = True ):
54
+ rightside_up = True , zorder = None ):
55
55
"""
56
56
Label a contour plot.
57
57
@@ -124,6 +124,12 @@ def clabel(self, levels=None, *,
124
124
of texts during the drawing time, therefore this can be used if
125
125
aspect of the axes changes.
126
126
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
+
127
133
Returns
128
134
-------
129
135
labels
@@ -144,6 +150,10 @@ def clabel(self, levels=None, *,
144
150
# Detect if manual selection is desired and remove from argument list.
145
151
self .labelManual = manual
146
152
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
147
157
148
158
if levels is None :
149
159
levels = self .levels
@@ -397,7 +407,7 @@ def _get_label_text(self, x, y, rotation):
397
407
dx , dy = self .ax .transData .inverted ().transform ((x , y ))
398
408
t = text .Text (dx , dy , rotation = rotation ,
399
409
horizontalalignment = 'center' ,
400
- verticalalignment = 'center' )
410
+ verticalalignment = 'center' , zorder = self . _clabel_zorder )
401
411
return t
402
412
403
413
def _get_label_clabeltext (self , x , y , rotation ):
@@ -411,7 +421,7 @@ def _get_label_clabeltext(self, x, y, rotation):
411
421
np .array ([[x , y ]]))
412
422
t = ClabelText (dx , dy , rotation = drotation [0 ],
413
423
horizontalalignment = 'center' ,
414
- verticalalignment = 'center' )
424
+ verticalalignment = 'center' , zorder = self . _clabel_zorder )
415
425
416
426
return t
417
427
@@ -869,7 +879,7 @@ def __init__(self, ax, *args,
869
879
self .allkinds = [None ] * len (self .allsegs )
870
880
871
881
# Default zorder taken from Collection
872
- zorder = kwargs .pop ('zorder' , 1 )
882
+ self . _contour_zorder = kwargs .pop ('zorder' , 1 )
873
883
for level , level_upper , segs , kinds in \
874
884
zip (lowers , uppers , self .allsegs , self .allkinds ):
875
885
paths = self ._make_paths (segs , kinds )
@@ -880,7 +890,7 @@ def __init__(self, ax, *args,
880
890
edgecolors = 'none' ,
881
891
alpha = self .alpha ,
882
892
transform = self .get_transform (),
883
- zorder = zorder )
893
+ zorder = self . _contour_zorder )
884
894
self .ax .add_collection (col , autolim = False )
885
895
self .collections .append (col )
886
896
else :
@@ -891,7 +901,7 @@ def __init__(self, ax, *args,
891
901
if aa is not None :
892
902
aa = (self .antialiased ,)
893
903
# Default zorder taken from LineCollection
894
- zorder = kwargs .pop ('zorder' , 2 )
904
+ self . _contour_zorder = kwargs .pop ('zorder' , 2 )
895
905
for level , width , lstyle , segs in \
896
906
zip (self .levels , tlinewidths , tlinestyles , self .allsegs ):
897
907
col = mcoll .LineCollection (
@@ -901,7 +911,7 @@ def __init__(self, ax, *args,
901
911
linestyles = [lstyle ],
902
912
alpha = self .alpha ,
903
913
transform = self .get_transform (),
904
- zorder = zorder )
914
+ zorder = self . _contour_zorder )
905
915
col .set_label ('_nolegend_' )
906
916
self .ax .add_collection (col , autolim = False )
907
917
self .collections .append (col )
0 commit comments