1111import matplotlib as mpl
1212from matplotlib import _api , _docstring
1313from matplotlib .backend_bases import MouseButton
14+ from matplotlib .text import Text
1415import matplotlib .path as mpath
1516import matplotlib .ticker as ticker
1617import matplotlib .cm as cm
1718import matplotlib .colors as mcolors
1819import matplotlib .collections as mcoll
1920import matplotlib .font_manager as font_manager
20- import matplotlib .text as text
2121import matplotlib .cbook as cbook
2222import matplotlib .patches as mpatches
2323import matplotlib .transforms as mtransforms
3131# per level.
3232
3333
34- class ClabelText (text . Text ):
34+ class ClabelText (Text ):
3535 """
3636 Unlike the ordinary text, the get_rotation returns an updated
3737 angle in the pixel coordinate assuming that the input rotation is
@@ -253,11 +253,10 @@ def _get_nth_label_width(self, nth):
253253 fig = self .axes .figure
254254 renderer = fig ._get_renderer ()
255255 return (
256- text .Text (0 , 0 ,
257- self .get_text (self .labelLevelList [nth ], self .labelFmt ),
258- figure = fig ,
259- size = self .labelFontSizeList [nth ],
260- fontproperties = self .labelFontProps )
256+ Text (0 , 0 , self .get_text (self .labelLevelList [nth ], self .labelFmt ),
257+ figure = fig ,
258+ size = self .labelFontSizeList [nth ],
259+ fontproperties = self .labelFontProps )
261260 .get_window_extent (renderer ).width )
262261
263262 @_api .deprecated ("3.5" )
@@ -267,8 +266,8 @@ def get_label_width(self, lev, fmt, fsize):
267266 lev = self .get_text (lev , fmt )
268267 fig = self .axes .figure
269268 renderer = fig ._get_renderer ()
270- width = (text . Text (0 , 0 , lev , figure = fig ,
271- size = fsize , fontproperties = self .labelFontProps )
269+ width = (Text (0 , 0 , lev , figure = fig ,
270+ size = fsize , fontproperties = self .labelFontProps )
272271 .get_window_extent (renderer ).width )
273272 width *= 72 / fig .dpi
274273 return width
@@ -419,10 +418,9 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
419418
420419 def _get_label_text (self , x , y , rotation ):
421420 dx , dy = self .axes .transData .inverted ().transform ((x , y ))
422- t = text .Text (dx , dy , rotation = rotation ,
423- horizontalalignment = 'center' ,
424- verticalalignment = 'center' , zorder = self ._clabel_zorder )
425- return t
421+ return Text (dx , dy , rotation = rotation ,
422+ horizontalalignment = 'center' ,
423+ verticalalignment = 'center' , zorder = self ._clabel_zorder )
426424
427425 def _get_label_clabeltext (self , x , y , rotation ):
428426 # x, y, rotation is given in pixel coordinate. Convert them to
@@ -585,6 +583,10 @@ def labels(self, inline, inline_spacing):
585583 if inline :
586584 paths [:] = additions
587585
586+ def remove (self ):
587+ for text in self .labelTexts :
588+ text .remove ()
589+
588590
589591def _is_closed_polygon (X ):
590592 """
@@ -1389,6 +1391,11 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True):
13891391
13901392 return (conmin , segmin , imin , xmin , ymin , d2min )
13911393
1394+ def remove (self ):
1395+ super ().remove ()
1396+ for coll in self .collections :
1397+ coll .remove ()
1398+
13921399
13931400@_docstring .dedent_interpd
13941401class QuadContourSet (ContourSet ):
0 commit comments