@@ -527,7 +527,7 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
527527 return rotation , nlc
528528
529529 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 ."""
531531 data_x , data_y = self .axes .transData .inverted ().transform ((x , y ))
532532 t = Text (
533533 data_x , data_y ,
@@ -538,20 +538,21 @@ def add_label(self, x, y, rotation, lev, cvalue):
538538 color = self .labelMappable .to_rgba (cvalue , alpha = self .get_alpha ()),
539539 fontproperties = self ._label_font_props ,
540540 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 )
541545 self .labelTexts .append (t )
542546 self .labelCValues .append (cvalue )
543547 self .labelXYs .append ((x , y ))
544548 # Add label to plot here - useful for manual mode label selection
545549 self .axes .add_artist (t )
546550
551+ @_api .deprecated ("3.8" , alternative = "add_label" )
547552 def add_label_clabeltext (self , x , y , rotation , lev , cvalue ):
548553 """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 )
555556
556557 def add_label_near (self , x , y , inline = True , inline_spacing = 5 ,
557558 transform = None ):
@@ -600,12 +601,6 @@ def pop_label(self, index=-1):
600601 t .remove ()
601602
602603 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-
609604 for idx , (icon , lev , cvalue ) in enumerate (zip (
610605 self .labelIndiceList ,
611606 self .labelLevelList ,
@@ -622,7 +617,7 @@ def labels(self, inline, inline_spacing):
622617 rotation , path = self ._split_path_and_get_label_rotation (
623618 subpath , idx , (x , y ),
624619 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.
626621 if inline : # If inline, add new contours
627622 additions .append (path )
628623 else : # If not adding label, keep old path
0 commit comments