Skip to content

[Bug]: The default animation.convert_args of ["-layers", "OptimizePlus"] breaks non-gif output #24268

@joh

Description

@joh

Bug summary

PR #23371 changed the default animation.convert_args to ["-layers", "OptimizePlus"] in order to better compress gif animations. However, animation.convert_args is also used by ImageMagickFileWriter to save frames as individual images (e.g., as png). Using -layers OptimizePlus in this case causes unintended cropping for some of the frames!

Code for reproduction

from matplotlib import animation

fig, ax = plt.subplots()

x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))

def animate(i):
    line.set_ydata(np.sin(x + i/10.0))  # update the data
    return line,

ani = animation.FuncAnimation(fig, animate, np.arange(1, 10), init_func=None, interval=25)

Writer = animation.writers['imagemagick_file']
writer = Writer()
#writer = Writer(extra_args=[]) # Workaround to disable -layers OptimizePlus
ani.save('ani.png', writer=writer)

Actual outcome

Frame (ani-0.png) 0 is correct, while frames 1-8 (ani-1.png through ani-8.png) are cropped.

Expected outcome

None of the frames should be cropped in the resulting images. See commented workaround in above code example.

Additional information

No response

Operating system

No response

Matplotlib Version

3.6.1

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions