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 want Figure._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!
Summary
Various methods require a renderer, in particular
get_tightbboxandget_window_extent. We have quite a few inconsistencies here.Many implementations of
get_window_extenthaverendereras an optional kwarg, and fallback: fallbacks areself.figure._cachedRenderer(Text,Legend) and some otherget_window_extentdon't need the renderer.get_tightbboxalways needs the renderer, but largely to pass toget_window_extentcalls onTextobjects.tight_layoutandconstrained_layoutneed the renderer, but that is only because they want to pass it to theget_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_cachedRendererorfig.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 callget_window_extent(renderer=different_renderer), but I have no idea what that use case is.get_window_extentmethods.get_window_extents: I'm not sure_cachedRendereris adequate, and we probably wantFigure._get_cachedRendererthat has some fallbacks in_cachedRendereris None, or fakes a draw to fill the cache.get_tightbboxmethods.This needs comment though from folks who understand the renderer system better: @QuLogic @anntzer @tacaswell ? Thanks!