Description
Summary
Various methods require a renderer, in particular get_tightbbox
and get_window_extent
. We have quite a few inconsistencies here.
Many implementations of get_window_extent
have renderer
as an optional kwarg, and fallback: fallbacks are self.figure._cachedRenderer
(Text
, Legend
) and some other get_window_extent
don't need the renderer.
get_tightbbox
always needs the renderer, but largely to pass to get_window_extent
calls on Text
objects.
tight_layout
and constrained_layout
need the renderer, but that is only because they want to pass it to the get_tightbbox
.
Proposed fix
It seems that we don't need to specify the renderer most of the time in get_window_extent
, but can safely fall back on the _cachedRenderer
or fig.canvas.get_renderer
, so it seems more consistent to just make this argument always optional. However, perhaps I'm missing a subtlety where the user may want to call get_window_extent(renderer=different_renderer)
, but I have no idea what that use case is.
- make renderer a kwarg in all
get_window_extent
methods. - improve the fallbacks in all the
get_window_extents
: I'm not sure_cachedRenderer
is adequate, and we probably wantFigure._get_cachedRenderer
that has some fallbacks in_cachedRenderer
is None, or fakes a draw to fill the cache. - make renderer an optional kwarg in all
get_tightbbox
methods.
This needs comment though from folks who understand the renderer system better: @QuLogic @anntzer @tacaswell ? Thanks!