diff --git a/lib/matplotlib/_tight_layout.py b/lib/matplotlib/_tight_layout.py index 192c2dcfdcb9..d61f827613bf 100644 --- a/lib/matplotlib/_tight_layout.py +++ b/lib/matplotlib/_tight_layout.py @@ -338,3 +338,15 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer, rect=(left, bottom, right, top)) return kwargs + + +def get_renderer(fig): + if fig._cachedRenderer: + return fig._cachedRenderer + else: + canvas = fig.canvas + if canvas and hasattr(canvas, "get_renderer"): + return canvas.get_renderer() + else: + from . import backend_bases + return backend_bases._get_renderer(fig)