@@ -527,7 +527,7 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
527
527
return rotation , nlc
528
528
529
529
def add_label (self , x , y , rotation , lev , cvalue ):
530
- """Add contour label without `.Text.set_transform_rotates_text` ."""
530
+ """Add a contour label, respecting whether *use_clabeltext* was set ."""
531
531
data_x , data_y = self .axes .transData .inverted ().transform ((x , y ))
532
532
t = Text (
533
533
data_x , data_y ,
@@ -538,20 +538,21 @@ def add_label(self, x, y, rotation, lev, cvalue):
538
538
color = self .labelMappable .to_rgba (cvalue , alpha = self .get_alpha ()),
539
539
fontproperties = self ._label_font_props ,
540
540
clip_box = self .axes .bbox )
541
+ if self ._use_clabeltext :
542
+ data_rotation , = self .axes .transData .inverted ().transform_angles (
543
+ [rotation ], [[x , y ]])
544
+ t .set (rotation = data_rotation , transform_rotates_text = True )
541
545
self .labelTexts .append (t )
542
546
self .labelCValues .append (cvalue )
543
547
self .labelXYs .append ((x , y ))
544
548
# Add label to plot here - useful for manual mode label selection
545
549
self .axes .add_artist (t )
546
550
551
+ @_api .deprecated ("3.8" , alternative = "add_label" )
547
552
def add_label_clabeltext (self , x , y , rotation , lev , cvalue ):
548
553
"""Add contour label with `.Text.set_transform_rotates_text`."""
549
- self .add_label (x , y , rotation , lev , cvalue )
550
- # Grab the last added text, and reconfigure its rotation.
551
- t = self .labelTexts [- 1 ]
552
- data_rotation , = self .axes .transData .inverted ().transform_angles (
553
- [rotation ], [[x , y ]])
554
- t .set (rotation = data_rotation , transform_rotates_text = True )
554
+ with cbook ._setattr_cm (self , _use_clabeltext = True ):
555
+ self .add_label (x , y , rotation , lev , cvalue )
555
556
556
557
def add_label_near (self , x , y , inline = True , inline_spacing = 5 ,
557
558
transform = None ):
@@ -600,12 +601,6 @@ def pop_label(self, index=-1):
600
601
t .remove ()
601
602
602
603
def labels (self , inline , inline_spacing ):
603
-
604
- if self ._use_clabeltext :
605
- add_label = self .add_label_clabeltext
606
- else :
607
- add_label = self .add_label
608
-
609
604
for idx , (icon , lev , cvalue ) in enumerate (zip (
610
605
self .labelIndiceList ,
611
606
self .labelLevelList ,
@@ -622,7 +617,7 @@ def labels(self, inline, inline_spacing):
622
617
rotation , path = self ._split_path_and_get_label_rotation (
623
618
subpath , idx , (x , y ),
624
619
label_width , inline_spacing )
625
- add_label (x , y , rotation , lev , cvalue ) # Really add label.
620
+ self . add_label (x , y , rotation , lev , cvalue ) # Really add label.
626
621
if inline : # If inline, add new contours
627
622
additions .append (path )
628
623
else : # If not adding label, keep old path
0 commit comments