Repository navigation
Fix Annotation.contains. - #12164
Merged
Merged
Fix Annotation.contains.#12164
Conversation
Annotation.contains always calls get_window_extents() without setting
the renderer arg, which is thus None (and this is implicitly allowed by
the signature of get_window_extents), but get_window_extents calls
update_positions which *requires* a non-None renderer (it ultimately
calls renderer.points_to_pixels).
Instead, reuse the code from Text.get_window_extents() which defaults to
the artist-or-figure renderer if the arg is None.
Example breaking code:
from matplotlib import pyplot as plt
ann = plt.annotate(
"foo", (.5, .5), arrowprops={"arrowstyle": "->"},
textcoords="offset points", xytext=(10, 10))
plt.gcf().canvas.mpl_connect(
"button_press_event", lambda event: print(ann.contains(event)))
plt.show()
and click anywhere to trigger an AttributeError.
jklymak
approved these changes
Sep 19, 2018
jklymak
left a comment
Member
There was a problem hiding this comment.
Modulo making these errors more verbose?
| if self._renderer is None: | ||
| self._renderer = self.figure._cachedRenderer | ||
| if self._renderer is None: | ||
| raise RuntimeError('Cannot get window extent w/o renderer') |
Member
There was a problem hiding this comment.
Should we be advising users to trigger a draw in these error messages?
Contributor
Author
There was a problem hiding this comment.
There's a few other places which already have a similar warning (Axes.draw_artist, Axes.redraw_in_frame) so I'd rather just factor it out to a helper method in a separate PR.
timhoffm
approved these changes
Sep 20, 2018
|
Something went wrong ... Please have a look at my logs. |
Contributor
|
@meeseeksdev backport to v3.0.x |
meeseeksmachine
pushed a commit
to meeseeksmachine/matplotlib
that referenced
this pull request
Sep 21, 2018
timhoffm
pushed a commit
that referenced
this pull request
Sep 21, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Annotation.contains always calls get_window_extents() without setting
the renderer arg, which is thus None (and this is implicitly allowed by
the signature of get_window_extents), but get_window_extents calls
update_positions which requires a non-None renderer (it ultimately
calls renderer.points_to_pixels).
Instead, reuse the code from Text.get_window_extents() which defaults to
the artist-or-figure renderer if the arg is None.
Example breaking code:
and click anywhere to trigger an AttributeError.
Regression due to #11801.
PR Summary
PR Checklist