
Recherche avancée
Médias (1)
-
La conservation du net art au musée. Les stratégies à l’œuvre
26 mai 2011
Mis à jour : Juillet 2013
Langue : français
Type : Texte
Autres articles (53)
-
MediaSPIP en mode privé (Intranet)
17 septembre 2013, parÀ partir de la version 0.3, un canal de MediaSPIP peut devenir privé, bloqué à toute personne non identifiée grâce au plugin "Intranet/extranet".
Le plugin Intranet/extranet, lorsqu’il est activé, permet de bloquer l’accès au canal à tout visiteur non identifié, l’empêchant d’accéder au contenu en le redirigeant systématiquement vers le formulaire d’identification.
Ce système peut être particulièrement utile pour certaines utilisations comme : Atelier de travail avec des enfants dont le contenu ne doit pas (...) -
Installation en mode ferme
4 février 2011, parLe mode ferme permet d’héberger plusieurs sites de type MediaSPIP en n’installant qu’une seule fois son noyau fonctionnel.
C’est la méthode que nous utilisons sur cette même plateforme.
L’utilisation en mode ferme nécessite de connaïtre un peu le mécanisme de SPIP contrairement à la version standalone qui ne nécessite pas réellement de connaissances spécifique puisque l’espace privé habituel de SPIP n’est plus utilisé.
Dans un premier temps, vous devez avoir installé les mêmes fichiers que l’installation (...) -
Installation en mode standalone
4 février 2011, parL’installation de la distribution MediaSPIP se fait en plusieurs étapes : la récupération des fichiers nécessaires. À ce moment là deux méthodes sont possibles : en installant l’archive ZIP contenant l’ensemble de la distribution ; via SVN en récupérant les sources de chaque modules séparément ; la préconfiguration ; l’installation définitive ;
[mediaspip_zip]Installation de l’archive ZIP de MediaSPIP
Ce mode d’installation est la méthode la plus simple afin d’installer l’ensemble de la distribution (...)
Sur d’autres sites (5965)
-
How to save animations with tight layout, transparency and in high quality
23 octobre 2023, par mapfI am trying to implement an option in my GUI to save an image sequence displayed using matplotlib. The code looks something like this :



import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import \
 FigureCanvasQTAgg as FigureCanvas
from matplotlib.animation import FuncAnimation
from PIL import Image


plt.rcParams['savefig.bbox'] = 'tight' 


class Printer:
 def __init__(self, data):
 self.fig, self.ax = plt.subplots()
 self.canvas = FigureCanvas(self.fig)

 # some irrelevant color adjustment here
 #self.ax.spines['bottom'].set_color('#f9f2d7')
 #self.ax.spines['top'].set_color('#f9f2d7')
 #self.ax.spines['right'].set_color('#f9f2d7')
 #self.ax.spines['left'].set_color('#f9f2d7')
 #self.ax.tick_params(axis='both', colors='#f9f2d7')
 #self.ax.yaxis.label.set_color('#f9f2d7')
 #self.ax.xaxis.label.set_color('#f9f2d7')
 #self.fig.subplots_adjust(left=0.1, right=0.975, bottom=0.09, top=0.98)
 self.fig.patch.set_alpha(0)
 self.fig.patch.set_visible(False)
 self.canvas.setStyleSheet("background-color:transparent;")
 self.fig.set_size_inches(10, 10, True)
 self.fig.tight_layout()

 self.data = data
 self.image_artist = self.ax.imshow(data[0])

 def animate(self, i):
 self.image_artist.set_data(self.data[i])
 self.canvas.draw()


def save_animation():
 data = [
 Image.open("test000.png"),
 Image.open("test001.png"),
 ]
 file = 'test.gif'
 printer = Printer(data)

 ani = FuncAnimation(
 printer.fig, printer.animate, interval=100, frames=len(data),
 )
 # writer = animation.writers['pillow'](bitrate=1000)
 ani.save(
 file, writer='pillow', savefig_kwargs={'transparent': True, 'bbox_inches': 'tight'}
 )


save_animation()




Transparency :



As you can see I have already tried several different approaches as suggested elsewhere (1, 2), but didn't manage to find a solution. All of the settings and arguments
patch.set_alpha(0)
,patch.set_visible(False)
,canvas.setStyleSheet("background-color:transparent;")
,savefig_kwargs={'transparent': True}
seem to have no effect at all on the transparency. I found this post but I didn't get the code to work (for one I had to comment out this%matplotlib inline
, but then I ended up getting some error during the MovieWriter.cleanupout = TextIOWrapper(BytesIO(out)).read() TypeError: a bytes-like object is required, not 'str'
). Here, it was suggested that this is actually a bug, but the proposed workaroud doesn't work for me since I would have to rely on third-party software. There also exists this bug report which was supposedly solved, so maybe it is unrelated.


Tight layout



I actually couldn't really find much on this, but all the things I tried (
plt.rcParams['savefig.bbox'] = 'tight'
,fig.tight_layout()
,savefig_kwargs={'bbox_inches': 'tight'}
) don't have any effect or are even actively discarded in the case of thebbox_inches argument
. How does this work ?


High quality



Since I cannot use
ImageMagick
and can't getffmpeg
to work (more on this below), I rely on pillow to save my animation. But the only argument in terms of quality that I can pass on seems to be thebitrate
, which doesn't have any effect. The files still have the same size and the animation still looks like mush. The only way that I found to increase the resolution was to usefig.set_size_inches(10, 10, True)
, but this still doesn't improve the overall quality of the animation. It still looks bad. I saw that you can pass oncodec
andextra_args
so maybe that is something that might help, but I have no idea how to use these because I couldn't find a list with allowed arguments.


ffmpeg



I can't get ffmpeg to work. I installed the python package from here and can import it into a python session but I don't know how I can get matplotlib to use that. I also got ffmpeg from here (Windows 64-bit version) and set the
plt.rcParams['animation.ffmpeg_path']
to where I saved the files (there was no intaller to run, not sure if I did it correctly). But this didn't help either. Also this is of course also third-party software, so if somebody else were to use my code/program it wouldn't work.

-
How to save animations with tight layout, transparency and in high quality with matplotlib ?
29 novembre 2019, par mapfI am trying to implement an option in my GUI to save an image sequence displayed using matplotlib. The code looks something like this :
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import \
FigureCanvasQTAgg as FigureCanvas
from matplotlib.animation import FuncAnimation
from PIL import Image
plt.rcParams['savefig.bbox'] = 'tight'
class Printer:
def __init__(self, data):
self.fig, self.ax = plt.subplots()
self.canvas = FigureCanvas(self.fig)
# some irrelevant color adjustment here
#self.ax.spines['bottom'].set_color('#f9f2d7')
#self.ax.spines['top'].set_color('#f9f2d7')
#self.ax.spines['right'].set_color('#f9f2d7')
#self.ax.spines['left'].set_color('#f9f2d7')
#self.ax.tick_params(axis='both', colors='#f9f2d7')
#self.ax.yaxis.label.set_color('#f9f2d7')
#self.ax.xaxis.label.set_color('#f9f2d7')
#self.fig.subplots_adjust(left=0.1, right=0.975, bottom=0.09, top=0.98)
self.fig.patch.set_alpha(0)
self.fig.patch.set_visible(False)
self.canvas.setStyleSheet("background-color:transparent;")
self.fig.set_size_inches(10, 10, True)
self.fig.tight_layout()
self.data = data
self.image_artist = self.ax.imshow(data[0])
def animate(self, i):
self.image_artist.set_data(self.data[i])
self.canvas.draw()
def save_animation():
data = [
Image.open("test000.png"),
Image.open("test001.png"),
]
file = 'test.gif'
printer = Printer(data)
ani = FuncAnimation(
printer.fig, printer.animate, interval=100, frames=len(data),
)
# writer = animation.writers['pillow'](bitrate=1000)
ani.save(
file, writer='pillow', savefig_kwargs={'transparent': True, 'bbox_inches': 'tight'}
)
save_animation()Transparency :
As you can see I have already tried several different approaches as suggested elsewhere (1, 2), but didn’t manage to find a solution. All of the settings and arguments
patch.set_alpha(0)
,patch.set_visible(False)
,canvas.setStyleSheet("background-color:transparent;")
,savefig_kwargs={'transparent': True}
seem to have no effect at all on the transparency. I found this post but I didn’t get the code to work (for one I had to comment out this%matplotlib inline
, but then I ended up getting some error during the MovieWriter.cleanupout = TextIOWrapper(BytesIO(out)).read() TypeError: a bytes-like object is required, not 'str'
). Here, it was suggested that this is actually a bug, but the proposed workaroud doesn’t work for me since I would have to rely on third-party software. There also exists this bug report which was supposedly solved, so maybe it is unrelated.Tight layout
I actually couldn’t really find much on this, but all the things I tried (
plt.rcParams['savefig.bbox'] = 'tight'
,fig.tight_layout()
,savefig_kwargs={'bbox_inches': 'tight'}
) don’t have any effect or are even actively discarded in the case of thebbox_inches argument
. How does this work ?High quality
Since I cannot use
ImageMagick
and can’t getffmpeg
to work (more on this below), I rely on pillow to save my animation. But the only argument in terms of quality that I can pass on seems to be thebitrate
, which doesn’t have any effect. The files still have the same size and the animation still looks like mush. The only way that I found to increase the resolution was to usefig.set_size_inches(10, 10, True)
, but this still doesn’t improve the overall quality of the animation. It still looks bad. I saw that you can pass oncodec
andextra_args
so maybe that is something that might help, but I have no idea how to use these because I couldn’t find a list with allowed arguments.ffmpeg
I can’t get ffmpeg to work. I installed the python package from here and can import it into a python session but I don’t know how I can get matplotlib to use that. I also got ffmpeg from here (Windows 64-bit version) and set the
plt.rcParams['animation.ffmpeg_path']
to where I saved the files (there was no intaller to run, not sure if I did it correctly). But this didn’t help either. Also this is of course also third-party software, so if somebody else were to use my code/program it wouldn’t work. -
Saving an animation using ffmpeg and matplotlib on anaconda3
21 juin 2016, par Varsha DyavaiahI am trying to create videos of NBA Action with Sportsvu data.
I was following the steps given in this blog by Dan Vatterott :
I am trying to create a animation and save it using ffmpeg and matplotlib.
The code snippet is attached below.import matplotlib.animation as animation
plt.rcParams['animation.ffmpeg_path'] = '/home/anaconda3/pkgs/ffmpeg-2.1.0-1/bin'
fig = plt.figure(figsize=(15,7.5)) #create figure object
ax = plt.gca() #create axis object
draw_court([0,100,0,50]) #draw the court
player_text = list(range(10)) #create player text vector
player_circ = list(range(10)) #create player circle vector
ball_circ = plt.Circle((0,0), 1.1, color=[1, 0.4, 0]) #create circle object for bal
for i in list(range(10)): #create circle object and text object for each player
col=['w','k'] if i<5 else ['k','w'] #color scheme
player_circ[i] = plt.Circle((0,0), 2.2, facecolor=col[0],edgecolor='k') #player circle
player_text[i] = ax.text(0,0,'',color=col[1],ha='center',va='center') #player jersey # (text)
ani = animation.FuncAnimation(fig, animate, frames=np.arange(0,np.size(ball_xy,0)), init_func=init, blit=True, interval=5, repeat=False,\
save_count=0) #function for making video
FFwriter = animation.FFMpegWriter()
ani.save('Event_%d.mp4' % (search_id),dpi=100,writer = FFwriter,fps=25) #function for saving video
plt.close('all') #close the plotWhen I try to save the animation ’ani’ , I get Errno 13 (Permission denied).
---------------------------------------------------------------------------
PermissionError Traceback (most recent call last)
in <module>()
17
18 FFwriter = animation.FFMpegWriter()
---> 19 ani.save('Event_%d.mp4' % (search_id),dpi=100,writer = FFwriter,fps=25) #function for saving video
20 plt.close('all') #close the plot
/home/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs)
799 # since GUI widgets are gone. Either need to remove extra code to
800 # allow for this non-existant use case or find a way to make it work.
--> 801 with writer.saving(self._fig, filename, dpi):
802 for anim in all_anim:
803 # Clear the initial frame
/home/anaconda3/lib/python3.5/contextlib.py in __enter__(self)
57 def __enter__(self):
58 try:
---> 59 return next(self.gen)
60 except StopIteration:
61 raise RuntimeError("generator didn't yield") from None
/home/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py in saving(self, *args)
192 '''
193 # This particular sequence is what contextlib.contextmanager wants
--> 194 self.setup(*args)
195 yield
196 self.finish()
/home/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py in setup(self, fig, outfile, dpi, *args)
182 # Run here so that grab_frame() can write the data to a pipe. This
183 # eliminates the need for temp files.
--> 184 self._run()
185
186 @contextlib.contextmanager
/home/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py in _run(self)
210 stdout=output, stderr=output,
211 stdin=subprocess.PIPE,
--> 212 creationflags=subprocess_creation_flags)
213
214 def finish(self):
/home/anaconda3/lib/python3.5/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
948 c2pread, c2pwrite,
949 errread, errwrite,
--> 950 restore_signals, start_new_session)
951 except:
952 # Cleanup if the child failed starting.
/home/anaconda3/lib/python3.5/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1542 else:
1543 err_msg += ': ' + repr(orig_executable)
-> 1544 raise child_exception_type(errno_num, err_msg)
1545 raise child_exception_type(err_msg)
1546
PermissionError: [Errno 13] Permission denied
</module>Can someone help me ? Thanks in advance.