Skip to content

Incompatibility with constrained layout? #11

Description

@guillaumedavidphd

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions