[Python] Matplotlib: Upgrade from 3.5.3 to 3.10.3 broke layout

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Matplotlib program, which plots pandas dataframes. It is running in a Docker container.

    I upgraded Python from 3.5 to 3.12 and Matplotlib from 3.5.3 to 3.10.3. I also upgraded Pandas in consequence.

    Since then, the PNG images resulting from it have their layouts broken:

    • Left and right margins are significantly lower than before
    • Bottom margin changed, resulting in some graphs having their legend not visible, or their top part cut off.

    All in all, the figure does not fit the canvas anymore.

    Here is the base code:

    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(10,10))
    fig.set_tight_layout(True)
    ax = plt.subplot(111)
    ax = df.plot(ax=ax, linewidth=3)

    # Legend code

    ...

    # End of legend code

    fig.canvas.print_figure('fig.png', bbox_inches='tight', format="png")



    Does Matplotlib 3.5+ have breaking changes in their layout engine that I am not aware of ?

    Continue reading...

Compartilhe esta Página