-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: AnnotationBbox extents before draw #26184
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
Conversation
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.
Minor suggestion, but otherwise looks good!
3c32a8b
to
2f58e49
Compare
I don't know what's going on with the Azure Linux tasks. If I click through to Azure it says they all succeeded. But they are currently showing for me as in progress below. |
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.
This seems correct to me, but I am a bit concerned about how to drive these objects to a state where they do not know what Figure
they are part of.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, hid my comment was working on the wrong branch 🤦🏻 |
@tacaswell has pointed out that if you take the code from the OP and use |
I can't reproduce that, and also @tacaswell mentioned that he was on the wrong branch? |
@tacaswell mentioned at the start of yesterday's call that he then tried with the right branch and it was still a problem (and I also reproduced it after the call). I have also now reproduced with multiple calls to import matplotlib.pyplot as plt
from matplotlib.offsetbox import AnnotationBbox, TextArea
fig, ax = plt.subplots(layout="constrained")
fig.set_facecolor('lightgray')
ab = AnnotationBbox(
TextArea("Some text", textprops={"size": 42}),
(1, 0.5),
xycoords="axes fraction",
box_alignment=(0.5, 0.5),
pad=0
)
ax.add_artist(ab)
plt.savefig("test1.png")
fig.set_size_inches(8, 3)
plt.savefig("test2.png")
plt.savefig("test3.png") I'm using QtAgg. Edit: if I run this with |
As there are issues I'm dismissing the review for now.
Oh, I see it's because it's at |
2f58e49
to
79250d1
Compare
Ok I think I have it. I probably need to go educate myself better about what @tomicapretto I think this also now fixes the case from tomicapretto/flexitext#11 (comment) |
Should I add a test for the draw-then-resize case? I'm not sure how realistic it is that a future contributor would break it in that specific way. |
I think this is fine without an additional test. |
…184-on-v3.7.x Backport PR #26184 on branch v3.7.x (FIX: AnnotationBbox extents before draw)
PR summary
Fixes #24453
Calling
update_positions
before working out the bbox withinget_tightbbox
means constrained layout will get sensible numbers to work with so the example from the issue works as expected. We can now also have constrained layout make space for the annotation if it is not contained within the axes:I'm not sure where
get_window_extent
is used, but I updated that in the same way for consistency (and to get the test passing after I removed the draw from it).Also split the test into two so that the two methods can be checked independently of each other.
PR checklist