11
11
import matplotlib as mpl
12
12
from matplotlib import _api , _docstring
13
13
from matplotlib .backend_bases import MouseButton
14
+ from matplotlib .text import Text
14
15
import matplotlib .path as mpath
15
16
import matplotlib .ticker as ticker
16
17
import matplotlib .cm as cm
17
18
import matplotlib .colors as mcolors
18
19
import matplotlib .collections as mcoll
19
20
import matplotlib .font_manager as font_manager
20
- import matplotlib .text as text
21
21
import matplotlib .cbook as cbook
22
22
import matplotlib .patches as mpatches
23
23
import matplotlib .transforms as mtransforms
31
31
# per level.
32
32
33
33
34
- class ClabelText (text . Text ):
34
+ class ClabelText (Text ):
35
35
"""
36
36
Unlike the ordinary text, the get_rotation returns an updated
37
37
angle in the pixel coordinate assuming that the input rotation is
@@ -253,11 +253,10 @@ def _get_nth_label_width(self, nth):
253
253
fig = self .axes .figure
254
254
renderer = fig ._get_renderer ()
255
255
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 )
261
260
.get_window_extent (renderer ).width )
262
261
263
262
@_api .deprecated ("3.5" )
@@ -267,8 +266,8 @@ def get_label_width(self, lev, fmt, fsize):
267
266
lev = self .get_text (lev , fmt )
268
267
fig = self .axes .figure
269
268
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 )
272
271
.get_window_extent (renderer ).width )
273
272
width *= 72 / fig .dpi
274
273
return width
@@ -419,10 +418,9 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
419
418
420
419
def _get_label_text (self , x , y , rotation ):
421
420
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 )
426
424
427
425
def _get_label_clabeltext (self , x , y , rotation ):
428
426
# x, y, rotation is given in pixel coordinate. Convert them to
@@ -585,6 +583,10 @@ def labels(self, inline, inline_spacing):
585
583
if inline :
586
584
paths [:] = additions
587
585
586
+ def remove (self ):
587
+ for text in self .labelTexts :
588
+ text .remove ()
589
+
588
590
589
591
def _is_closed_polygon (X ):
590
592
"""
@@ -1389,6 +1391,11 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True):
1389
1391
1390
1392
return (conmin , segmin , imin , xmin , ymin , d2min )
1391
1393
1394
+ def remove (self ):
1395
+ super ().remove ()
1396
+ for coll in self .collections :
1397
+ coll .remove ()
1398
+
1392
1399
1393
1400
@_docstring .dedent_interpd
1394
1401
class QuadContourSet (ContourSet ):
0 commit comments