@@ -263,11 +263,19 @@ def set_offset(self, xy):
263263 xy : (float, float) or callable
264264 The (x, y) coordinates of the offset in display units. These can
265265 either be given explicitly as a tuple (x, y), or by providing a
266- function that converts the extent into the offset. This function
267- must have the signature::
266+ function that dynamically computes an offset (taking the arguments
267+ passed to `.OffsetBox.get_offset`). It is recommended to make such
268+ functions take no arguments.
269+
270+ Before version 3.6, the callable had to have the signature::
268271
269272 def offset(width, height, xdescent, ydescent, renderer) \
270273 -> (float, float)
274+
275+ For backwards compatibility, callables with arbitrary signatures
276+ are currently accepted as long as compatible arguments are
277+ passed in calls to `.set_offset`. This should be considered an
278+ implementation detail, and may be deprecated in the future.
271279 """
272280 self ._offset = xy
273281 self .stale = True
@@ -276,9 +284,12 @@ def get_offset(self, *args, **kwargs):
276284 """
277285 Return the (x, y) offset.
278286
279- Parameters must be passed if the offset is dynamically determined by a
280- callable (see `~.OffsetBox.set_offset`), and are forwarded to that
281- callable.
287+ Parameters are usually not necessary. The only exception can occur
288+ if you have defined a callable to calculate the offset dynamically (see
289+ `~.OffsetBox.set_offset`). It is now recommended that such a
290+ callable does not take parameters. However, for backward-compatibility,
291+ callables with parameters are still supported; these parameters must be
292+ provided to `.get_offset` so that we can pass them on.
282293 """
283294 return (self ._offset (* args , ** kwargs ) if callable (self ._offset )
284295 else self ._offset )
@@ -340,7 +351,7 @@ def get_extent(self, renderer):
340351 def get_window_extent (self , renderer ):
341352 # docstring inherited
342353 w , h , xd , yd = self .get_extent (renderer )
343- px , py = self .get_offset (w , h , xd , yd , renderer )
354+ px , py = self .get_offset ()
344355 return mtransforms .Bbox .from_bounds (px - xd , py - yd , w , h )
345356
346357 def draw (self , renderer ):
@@ -349,7 +360,7 @@ def draw(self, renderer):
349360 to the given *renderer*.
350361 """
351362 w , h , xdescent , ydescent , offsets = self .get_extent_offsets (renderer )
352- px , py = self .get_offset (w , h , xdescent , ydescent , renderer )
363+ px , py = self .get_offset ()
353364 for c , (ox , oy ) in zip (self .get_visible_children (), offsets ):
354365 c .set_offset ((px + ox , py + oy ))
355366 c .draw (renderer )
@@ -530,7 +541,7 @@ def get_extent_offsets(self, renderer):
530541 def draw (self , renderer ):
531542 # docstring inherited
532543 w , h , xdescent , ydescent , offsets = self .get_extent_offsets (renderer )
533- px , py = self .get_offset (w , h , xdescent , ydescent , renderer )
544+ px , py = self .get_offset ()
534545 for c , (ox , oy ) in zip (self .get_visible_children (), offsets ):
535546 c .set_offset ((px + ox , py + oy ))
536547
@@ -1036,9 +1047,10 @@ def get_window_extent(self, renderer):
10361047 # docstring inherited
10371048 # Update the offset func, which depends on the dpi of the renderer
10381049 # (because of the padding).
1050+ w , h , xd , yd = self .get_extent (renderer )
10391051 fontsize = renderer .points_to_pixels (self .prop .get_size_in_points ())
10401052
1041- def _offset (w , h , xd , yd , renderer ):
1053+ def _offset (* args , ** kwargs ): # args are ignored; left for backcompat.
10421054 bbox = Bbox .from_bounds (0 , 0 , w , h )
10431055 pad = self .borderpad * fontsize
10441056 bbox_to_anchor = self .get_bbox_to_anchor ()
@@ -1064,9 +1076,7 @@ def draw(self, renderer):
10641076 self .update_frame (bbox , fontsize )
10651077 self .patch .draw (renderer )
10661078
1067- width , height , xdescent , ydescent = self .get_extent (renderer )
1068-
1069- px , py = self .get_offset (width , height , xdescent , ydescent , renderer )
1079+ px , py = self .get_offset ()
10701080
10711081 self .get_child ().set_offset ((px , py ))
10721082 self .get_child ().draw (renderer )
@@ -1545,8 +1555,7 @@ def __init__(self, ref_artist, offsetbox, use_blit=False):
15451555 def save_offset (self ):
15461556 offsetbox = self .offsetbox
15471557 renderer = offsetbox .figure ._cachedRenderer
1548- w , h , xd , yd = offsetbox .get_extent (renderer )
1549- offset = offsetbox .get_offset (w , h , xd , yd , renderer )
1558+ offset = offsetbox .get_offset ()
15501559 self .offsetbox_x , self .offsetbox_y = offset
15511560 self .offsetbox .set_offset (offset )
15521561
0 commit comments