-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Hint at draw_without_rendering() in Text.get_window_extent #22122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()``. | ||
Comment on lines
+886
to
+887
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Saving is usually not a good way to trigger a draw in this case. You'll likely want to modify the figure somehow based on the extent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm 50/50 about including plt.ion()
for j in range(5):
fig, ax = plt.subplots()
plt.show()
sleep(5) will not spin the GUI event loop (and hence in some cases not get the actual render to happen) until after the loop is done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, but 99.999% of cases, a draw will occur! |
||
|
||
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
draw
link would go to Text.draw which is more or less an internal API and not helpful here (at worst the user might try and call that). It's better to not link to anything here.