Skip to content

Error at save animation with pillow #15678

@Zachary4biz

Description

@Zachary4biz

Bug report

Bug summary

line 575 of animation.py use Image.frombytes to load a BytesIO, this will lead to an exception -- not enough image data.
seems we can't feed bytes of .png to frombytes from the first question-comment of this SO question

Code for reproduction

import numpy as np
from matplotlib import animation
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

emb = np.random.random_sample((1000,3))

fig = plt.figure("bug_report")
ax = Axes3D(fig)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_xlim3d(left=-1,right=1)
ax.set_ylim3d(bottom=-1,top=1)
ax.set_zlim3d(bottom=-1,top=1)

batch=50
def animate(i):
    emb_part = emb[i*batch:(i+1)*batch]
    ax.scatter(xs=emb_part[:, 0], ys=emb_part[:, 1], zs=emb_part[:, 2])
    return ax

ani = animation.FuncAnimation(fig=fig, func=animate, frames=len(emb)//batch + 1, interval=0.01*1000, blit=False, repeat=False)

ani.save("/Users/zac/Downloads/ani.gif", fps=30, writer='pillow')

Actual outcome

# ....
ValueError: not enough image data

During handling of the above exception, another exception occurred:
# ....

actually, if we use plt.show() before ani.save, this exception wont appear, but we will get only some last parts of the animation, example as this

Expected outcome

normally saved gif pic
example as this

Matplotlib version

  • Operating system: MacOSX
  • Matplotlib version: 3.0.3
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7.3
  • Jupyter version (if applicable):
  • Other libraries: numpy

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy