flexitext: Incompatibility with `constrained` layout?
I think I found a bug when using Matplotlib’s constrained layout and flexitext. In this case, flexitext makes the layout very inconsistent if the window is resized, and different from what is expected. Here’s some example code:
import matplotlib.pyplot as plt
from flexitext import flexitext
fig, ax = plt.subplots(1, 2, figsize=(12, 6), layout="constrained")
text1 = "<size:42, name:Carlito>Some<color:#11557c, weight:bold> text</></>"
text2 = "<size:36, name:Lato, color:royalblue><weight:bold>Here</> too</>"
flexitext(0.5, 0.5, text1, ha="center", ax=ax[0])
flexitext(0.5, 0.5, text2, ha="center", ax=ax[1])
fig.set_facecolor("w")
# fig.savefig("example.png", dpi=300)
plt.show()
Here is a screenshot of the result:

After maximizing the window, and going back to its original size, the layout has changed:

Maximizing again, and going back to the original size:

Note that uncommenting fig.savefig("example.png", dpi=300) triggers a canvas draw and improves the layout for the given window size, but it doesn’t seem to be what the layout would be without the flexitext.
Expected layout:

Layout after a canvas draw:

What do you think?
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (10 by maintainers)
@guillaumedavidphd Matplotlib devs are fixing this issue here https://github.com/matplotlib/matplotlib/pull/26184. I still see the warning but now it works.
@rcomer I confirm the problems I reported disappeared (in reply to this https://github.com/matplotlib/matplotlib/pull/26184#issuecomment-1614459856)
thanks a lot!
Unfortunately it turned out that there are still problems with the basic case, see https://github.com/matplotlib/matplotlib/pull/26184#issuecomment-1614154687.
Great to hear!
I opened this https://discourse.matplotlib.org/t/constrained-layout-does-not-work-well-with-annotationbbox/23301