Skip to content

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

Merged
merged 1 commit into from
Jan 6, 2022

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Jan 6, 2022

No description provided.

@@ -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
Copy link
Member Author

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.

Comment on lines +886 to +887
trigger a draw first, e.g. by calling
`~.Figure.draw_without_rendering` or ``plt.show()``.
Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 50/50 about including plt.show() as

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but 99.999% of cases, a draw will occur!

@timhoffm timhoffm added this to the v3.6.0 milestone Jan 6, 2022
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a minor comment, but 👍 on it going in as is.

@jklymak jklymak merged commit 0548b11 into matplotlib:main Jan 6, 2022
@timhoffm timhoffm deleted the get_window_extent branch January 6, 2022 13:28
@timhoffm timhoffm mentioned this pull request Jan 6, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants