@@ -284,13 +284,28 @@ def update_from(self, other):
284284 self ._linespacing = other ._linespacing
285285 self .stale = True
286286
287+ def _get_layout_cache_key (self , renderer = None ):
288+ """
289+ Return a hashable tuple of properties that lets `_get_layout` know
290+ whether a previously computed layout can be reused.
291+ """
292+ x , y = self .get_unitless_position ()
293+ renderer = renderer or self ._renderer
294+ return (
295+ x , y , self .get_text (), hash (self ._fontproperties ),
296+ self ._verticalalignment , self ._horizontalalignment ,
297+ self ._linespacing ,
298+ self ._rotation , self ._rotation_mode , self ._transform_rotates_text ,
299+ self .figure .dpi , weakref .ref (renderer ),
300+ )
301+
287302 def _get_layout (self , renderer ):
288303 """
289304 Return the extent (bbox) of the text together with
290305 multiple-alignment information. Note that it returns an extent
291306 of a rotated text when necessary.
292307 """
293- key = self .get_prop_tup (renderer = renderer )
308+ key = self ._get_layout_cache_key (renderer = renderer )
294309 if key in self ._cached :
295310 return self ._cached [key ]
296311
@@ -831,6 +846,8 @@ def get_position(self):
831846 # specified with 'set_x' and 'set_y'.
832847 return self ._x , self ._y
833848
849+ # When removing, also remove the hash(color) check in set_color()
850+ @_api .deprecated ("3.5" )
834851 def get_prop_tup (self , renderer = None ):
835852 """
836853 Return a hashable tuple of properties.
@@ -938,7 +955,8 @@ def set_color(self, color):
938955 # out at draw time for simplicity.
939956 if not cbook ._str_equal (color , "auto" ):
940957 mpl .colors ._check_color_like (color = color )
941- # Make sure it is hashable, or get_prop_tup will fail.
958+ # Make sure it is hashable, or get_prop_tup will fail (remove this once
959+ # get_prop_tup is removed).
942960 try :
943961 hash (color )
944962 except TypeError :
0 commit comments