Skip to content

[MNT]: sort out renderers #22744

Open
Open
@jklymak

Description

@jklymak

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.

  1. make renderer a kwarg in all get_window_extent methods.
  2. 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.
  3. 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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions