
Recherche avancée
Autres articles (29)
-
Participer à sa traduction
10 avril 2011Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
Actuellement MediaSPIP n’est disponible qu’en français et (...) -
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
Participer à sa documentation
10 avril 2011La documentation est un des travaux les plus importants et les plus contraignants lors de la réalisation d’un outil technique.
Tout apport extérieur à ce sujet est primordial : la critique de l’existant ; la participation à la rédaction d’articles orientés : utilisateur (administrateur de MediaSPIP ou simplement producteur de contenu) ; développeur ; la création de screencasts d’explication ; la traduction de la documentation dans une nouvelle langue ;
Pour ce faire, vous pouvez vous inscrire sur (...)
Sur d’autres sites (5468)
-
Animation freezes after a number of frames after upgrading Matplotlib
9 mars 2018, par Oliver von BaronI recently updated my matplotlib python package to version 2.2.0, and now some previously working code to save an animation does not work. Instead of saving an animation, the code freezes at a certain iteration number. It becomes unresponsive to interrupts and throws a PyEval_RestoreThread fatal error when I manage to close the command window.
I am using Enthought Canopy. The code still works as normal with other versions of python and matplotlib.
I can replicate the problem with this :
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
SIZE = 128
fig, ax = plt.subplots()
ims = ax.imshow(np.random.rand(SIZE, SIZE))
i = 0
def update_animation(*args):
global i
i = i + 1
image = np.random.rand(SIZE, SIZE)
ims.set_data(image)
print "Iteration "+str(i)
F_NAME = "anim_test.mp4"
NUM_ITERS = 1000
FFwriter = animation.FFMpegWriter(fps=6, bitrate=500)
anim=animation.FuncAnimation(fig,update_animation,frames=NUM_ITERS,blit=False, repeat=False, interval=200)
anim.save(F_NAME, writer=FFwriter)
print "saved animation to " + F_NAMEChanging the bitrate parameter changed the number of the frame the program halts at. For bitrate=500, it halts around frame 46.
How can I stop pyplot freezing before all frames can be saved ?
EDIT
My system details :
Python 2.7.6 64bit Enthought Canopy
Windows 8
8GB RAM
ffmpeg version N-79075-ga7b8a6e -
Exception in Tkinter callback while saving animation with matplotlib
24 août 2017, par paulI’m a little hesitant about asking this, since there seem to be many "Exception in Tkinter callback" questions, but I cannot find one that fits the problem I have here.
I am trying to save an MP4 animation (of a percolation simulation) using matplotlib with ffmpeg. The code works fine on my home laptop, but not on my work PC. It also works fine if I replace the
anim.save
line withplt.show()
, but I do want to save the animation. I’m using Python 3.5.2 on Ubuntu 17.04 (and I have ffmpeg installed).Here is the error :
>>> Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 1558, in __call__
return self.func(*args)
File "/usr/lib/python3.5/tkinter/__init__.py", line 604, in callit
func(*args)
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 373, in idle_draw
self.draw()
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 354, in draw
FigureCanvasAgg.draw(self)
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 474, in draw
self.figure.draw(self.renderer)
File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 62, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 1165, in draw
self.canvas.draw_event(renderer)
File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 1809, in draw_event
self.callbacks.process(s, event)
File "/usr/lib/python3/dist-packages/matplotlib/cbook.py", line 563, in process
proxy(*args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/cbook.py", line 430, in __call__
return mtd(*args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/animation.py", line 661, in _start
self._init_draw()
File "/usr/lib/python3/dist-packages/matplotlib/animation.py", line 1221, in _init_draw
self._draw_frame(next(self.new_frame_seq()))
StopIterationThe code producing the error is :
def percolate():
# initialize an instance of the Percolator class
perc = Percolator(1, 100, 0.1)
# initialize the image
fig, ax = plt.subplots()
im = plt.imshow(perc.states)
anim = animation.FuncAnimation(fig, perc.update, perc.update_iter, repeat=False, fargs=(im, ), save_count=perc.n**2)
anim.save("perc.mp4")I can reproduce the code for the
Percolator
class if necessary, but that part is working fine. It has two functions :update_iter
, a generator function that yieldsTrue
as long as the animation should continue, andupdate
, which takes (the result of the iterator and)im
as inputs, and its last two lines areim.set_array(self.states)
return im,UPDATE :
Here’s an MWE.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
class Percolator:
def __init__(self):
self.i = 0
self.states = np.zeros((10, 10))
self.end = False
def update(self, garbage=None, im=None):
self.i += 1
if self.i == 10:
self.end = True
im.set_array(self.states)
return im,
def update_iter(self):
while self.end == False:
yield True
def percolate():
perc = Percolator()
fig, ax = plt.subplots()
im = plt.imshow(perc.states)
anim = animation.FuncAnimation(fig, perc.update, perc.update_iter, repeat=False, \
fargs=(im, ), save_count=100)
anim.save("perc.gif", writer="imagemagick")In this example, the
Percolator
class doesn’t do anything interesting - it sets up a 10x10 grid of 0s, and each call to itsupdate
function sets the image to the same 10x10 grid.If the
frames
attribute of FuncAnimation is set to 50 (say), rather than toperc.update_iter
, then there is no error and the image is saved correctly. So the problem seems to be with my generator function. I want to use the generator function because I want to keep creating new frames until some condition onperc.states
is met - here, boringly, I’ve just asked it to keep going for 10 iterations.System details : Python 3.5.3, matplotlib 2.0.0, Ubuntu 17.04.
UPDATE 2 :
Same problem after upgrading to matplotlib 2.0.2. Also, printing some output along the way reveals that the error occurs at the end of the iterations. In fact, if
update_iter
is changed to :def update_iter(self):
print(self.end)
while self.end == False:
yield True... then the output is :
False
False
False
False
False
False
False
False
False
False
False
True
>>> True
Exception in Tkinter callback
Traceback (most recent call last):
etc. -
Matplotlib animation error : Requested MovieWriter (ffmpeg) not available, while ffmpeg is installed
3 juillet 2020, par Vivien BonnotI'm trying to animate colormapping representations of parametric complex fonctions using Python.
I gradually put some things together, and checked that they worked properly. But I can't get the animation to be saved.


I encountered this error :


Requested MovieWriter (ffmpeg) not available


However, ffmpeg is indeed installed on my system,
on Windows console
ffmpeg -version
returns all sorts of informations about ffmpeg. Additionnaly, I also installed ffmpeg in Python scripts directory using pippip install ffmpeg
, which was successfull. I also set up ffmepg path in my code :plt.rcParams['animation.ffmpeg_path'] = "C:\FFmpeg\bin\ffmpeg.exe"


I'm runing out of ideas.


Here is my code.
Thank you for reading.


import numpy as np
import math
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
pi=math.pi
plt.rcParams['animation.ffmpeg_path'] = "C:\FFmpeg\bin\ffmpeg.exe"
fig = plt.figure()

def complex_array_to_rgb(X, theme='dark', rmax=None):
 absmax = rmax or np.abs(X).max()
 Y = np.zeros(X.shape + (3,), dtype='float')
 Y[..., 0] = np.angle(X) / (2 * pi) % 1
 if theme == 'light':
 Y[..., 1] = np.clip(np.abs(X) / absmax, 0, 1)
 Y[..., 2] = 1
 elif theme == 'dark':
 Y[..., 1] = 1
 Y[..., 2] = np.clip(np.abs(X) / absmax, 0, 1)
 Y = matplotlib.colors.hsv_to_rgb(Y)
 return Y

# Set up formatting for the movie files
Writer = animation.writers['ffmpeg']
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)

fps = 10
nSeconds = 1
snapshots = [ complex_array_to_rgb(np.array([[3*(x + 1j*y)**(2.9+p/300) + 1/(x + 1j*y)**2 for x in np.arange(-1,1,0.05)] for y in np.arange(-1,1,0.05)])) for p in range( nSeconds * fps ) ]

fig = plt.figure( figsize=(3,3) )

Z2=snapshots[0]
im=plt.imshow(Z2, extent=(-1,1,-1,1))

def animate_func(i):
 if i % fps == 0:
 print( '.')

 im.set_array(snapshots[i])
 return [im]
 
anim = animation.FuncAnimation(
 fig, 
 animate_func, 
 frames = nSeconds * fps,
 interval = 1000 / fps, # in ms
 )

anim.save('test_anim.mp4', writer=writer)