FIX: ignore invisible gridliner labels in title adjustment#2667
FIX: ignore invisible gridliner labels in title adjustment#2667rcomer merged 1 commit intoSciTools:mainfrom
Conversation
greglucas
left a comment
There was a problem hiding this comment.
This seems like a good thing to do anyways, but I'm wondering if we want to do the bbox union instead of max like you mentioned just below this to be more robust there too? That can be a future PR too, feel free to merge as is.
|
Looks like it is faster to only consider the ymax, although I only tried with one example. Also most of the slowdown came from having the null bboxes in the union. |
Should you not be doing the union once at the end instead of each time in the loop? |
oh yes 🤦♀️ |
|
I think I did it right this time, and only considering the ymax still comes out fastest, though these numbers are not large in the scheme of things: drawing the whole figure from the test with |
Rationale
Since matplotlib/matplotlib#31285,
Textobjects return a null bbox if they are invisible or have an empty string. This broke our title positioning logic, because we specifically look at theymaxof the Bbox rather than taking box unions.The invalid title position gets incorporated into the axes tight bbox, which also becomes invalid and therefore messes up constrained layout and we get a plot like #2666 (comment) where the titles have disappeared and the gridline labels overlap each other or go off the side of the plot.
This can all be avoided if we ignore the invisible or empty labels. Running the relevant test locally with this branch and Elliot's branch from matplotlib/matplotlib#31521, I got a sensible image
Implications
This clearly won't help anyone who uses existing Cartopy releases with the new Matplotlib release.