From 9477aae4ead816faa44800d729a4ebfceaa7e7c3 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 6 Jan 2022 01:32:57 +0100 Subject: [PATCH] Hint at draw_without_rendering() in Text.get_window_extent --- lib/matplotlib/text.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index a8e4ef88bbeb..66cc6c046ba6 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -882,8 +882,9 @@ def get_window_extent(self, renderer=None, dpi=None): A renderer is needed to compute the bounding box. If the artist has already been drawn, the renderer is cached; thus, it is only necessary to pass this argument when calling `get_window_extent` - before the first `draw`. In practice, it is usually easier to - trigger a draw first (e.g. by saving the figure). + before the first draw. In practice, it is usually easier to + trigger a draw first, e.g. by calling + `~.Figure.draw_without_rendering` or ``plt.show()``. dpi : float, optional The dpi value for computing the bbox, defaults to @@ -904,7 +905,9 @@ def get_window_extent(self, renderer=None, dpi=None): if self._renderer is None: self._renderer = self.figure._cachedRenderer if self._renderer is None: - raise RuntimeError('Cannot get window extent w/o renderer') + raise RuntimeError( + "Cannot get window extent of text w/o renderer. You likely " + "want to call 'figure.draw_without_rendering()' first.") with cbook._setattr_cm(self.figure, dpi=dpi): bbox, info, descent = self._get_layout(self._renderer)