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: Screenshot from 2022-11-08 14-34-27

After maximizing the window, and going back to its original size, the layout has changed: Screenshot from 2022-11-08 14-34-36

Maximizing again, and going back to the original size: Screenshot from 2022-11-08 14-34-40

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: Screenshot from 2022-11-08 14-39-11

Layout after a canvas draw: Screenshot from 2022-11-08 14-39-23

What do you think?

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

@guillaumedavidphd Matplotlib devs are fixing this issue here https://github.com/matplotlib/matplotlib/pull/26184. I still see the warning but now it works.

example_full

@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!