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
[Bug]: AnnotationBbox does not return correct window_extent before first draw #24453
Comments
Try Probably an easy todo here is to be more explicit about Edit: sorry I see that you know about `set_in_layout(False). What bug are you reporting then? |
Why does an annotation box in an Axes who's content is also fully inside the Axes cause constrained layout to grow confused? |
Not sure. I assume AnnotationBox doesn't know it's bounding box until after a draw? If you force a draw everything is fine. Btw doubt this is unique to constrained_layout. |
If you do I'll maintain these are pretty low-level artists, and obviously they do not conform to the standard tight_bbox and draw behaviour. I'm not sure how far someone wants to go to fix that. |
Confirmed same result for |
ok, so the issue is that:
I agree that this is an edge case and it may not be worth the complexity required to solve this in a general way. Maybe just a note in the |
I think thats right. We could factor the logic that does the placement out of the draw, and call that when the extent is asked for. I think it's fair that the child doesn't know where it is, but the parent should be able to figure it out without having to do a whole draw. But as it is, We could add a comment about this until someone feels like fixing it. |
Wow, thanks a lot for the debate and the research. Really illuminating! Feel free to do whatever you think it's better with this issue (closing, leaving open until someone fixes it, changing title, etc). This appeared when someone reported an issue in a library I wrote tomicapretto/flexitext#11 and internally we include text using |
The warning has been around for a while, but its trigger did change slightly in #22289. I have not checked, but possibly this PR introduced the change. |
I just had my first go with |
That seems like a likely place! |
I can no longer reproduce the warning on Although we don't get the warning any more, we can still see from the plot that constrained layout is not being applied. |
Actually, I'm starting to think the warning was a red herring: the second plot at #24453 (comment) and the one in my previous comment are consistent with constrained layout having run and made space for the annotation on the lower left of the axes. If it had not run, there would surely be more space top and right. |
Bug summary
I’m trying to use a constrained layout in a visualization that contains an artist that is an instance of AnnotationBbox, and matplotlib raises a warning saying constrained layout is not applied. The visual effect is not evident in this simple example, but it becomes very clear once we have multiple panels.
Code for reproduction
Actual outcome
UserWarning: constrained_layout not applied because axes sizes collapsed to zero. Try making figure larger or axes decorations smaller.
Expected outcome
No warning should appear
Additional information
The following works without any warning
The problem with the constrained layout is more evident if I have two or more panels.
One way of fixing it (i.e. getting rid of the warning and bad functionality) is to do ab.set_in_layout(False) before doing ax.add_artist(ab).
This was first posted on Discourse https://discourse.matplotlib.org/t/constrained-layout-does-not-work-well-with-annotationbbox/23301
Operating system
Ubuntu 22
Matplotlib Version
3.6.2
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: