Recherche avancée

Médias (91)

Autres articles (49)

  • Emballe Médias : Mettre en ligne simplement des documents

    29 octobre 2010, par

    Le plugin emballe médias a été développé principalement pour la distribution mediaSPIP mais est également utilisé dans d’autres projets proches comme géodiversité par exemple. Plugins nécessaires et compatibles
    Pour fonctionner ce plugin nécessite que d’autres plugins soient installés : CFG Saisies SPIP Bonux Diogène swfupload jqueryui
    D’autres plugins peuvent être utilisés en complément afin d’améliorer ses capacités : Ancres douces Légendes photo_infos spipmotion (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-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

  • Encoding and processing into web-friendly formats

    13 avril 2011, par

    MediaSPIP automatically converts uploaded files to internet-compatible formats.
    Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
    Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
    Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
    All uploaded files are stored online in their original format, so you can (...)

Sur d’autres sites (6365)

  • ValueError : Image size of 100010x50004 pixels is too large. It must be less than 2^16 in each direction

    3 avril 2021, par Slow

    I am using matplotlib.pyplot to plot an animation video from data files.
Below is my code, I am getting this error each time I run the code.

    


    


    ValueError : Image size of 100010x50004 pixels is too large. It must be
less than 2^16 in each direction.

    


    


    According to some suggestions, I have restarted my kernel and update it, but still getting this issue.

    


    import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib.animation import FFMpegWriter
import matplotlib.pyplot as plt
import numpy as np
import readArray as ra
# import polygon as poly

def fieldMovie( fid, sx, sy, dt):
    """
    save the field and vesicle deformation movie
    
    input: 
        fid: name
        sx, sy: coordinates
        dt: time step

    Returns
    -------
    None.

    """
    # sx = ra.readArray('sx.afdat')
    # sy = ra.readArray('sy.afdat') 
    xbon = ra.readArray('xbound.afdat')
    ybon = ra.readArray('ybound.afdat')
    
    Tend = int(len(sx)/1)
    m = 1350
    n = 135
    x = np.arange(0, m)
    y = np.arange(0, n)
    X, Y = np.meshgrid(x, y)
    
    metadata = dict(title='field', artist='Matplotlib', 
                    comment='draw field')
    writer = FFMpegWriter(fps=7, metadata=metadata)
    
    fig = plt.figure(figsize=(10, 5))
    with writer.saving(fig, fid, Tend):
        for i in range(0, 9999, 2):
            time = dt*i
            fig.clf()
            sx_this = sx[i]
            sx_this = np.r_[sx_this, [sx_this[0,:]]]
            sy_this = sy[i]
            sy_this = np.r_[sy_this, [sy_this[0,:]]]
            sx_min = np.min(sx_this, axis=0)
            sx_this = sx_this - np.floor(sx_min/m)*m
        
            plt.fill(sx_this, sy_this, 'r', linewidth=1.5)
            sx_this = sx_this - m
            plt.fill(sx_this, sy_this, 'r', linewidth=1.5)
            plt.plot(xbon, ybon, '.' ,color = 'k' , markersize=1.0)
            plt.axis('equal')
            plt.axis('on')
            plt.xlim(0, m-1)
            title1 = 'test '
            title2 = 'at T = %.4f s, Ht = 18%%' % time
            plt.title(title1+title2, fontsize=16, fontweight='bold')
            ax = plt.gca()
            ax.set_position([0.05, 0.05, 0.8, 0.85])
            plt.pause(0.1)
            writer.grab_frame()
            plt.axes().set_aspect('equal')
            
sx = ra.readArray('sx.afdat')
sy = ra.readArray('sy.afdat')
dt = 0.002 * 1.5e-7 / 0.0003 * 700001 / 10000
fieldMovie('Animation.mp4', sx, sy, dt)


    


  • How to save animations with tight layout, transparency and in high quality

    23 octobre 2023, par mapf

    I 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.cleanup out = 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 the bbox_inches argument. How does this work ?

    



    High quality

    



    Since I cannot use ImageMagick and can't get ffmpeg 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 the bitrate, 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 use fig.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 on codec and extra_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 mapf

    I 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.cleanup out = 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 the bbox_inches argument. How does this work ?

    High quality

    Since I cannot use ImageMagick and can’t get ffmpeg 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 the bitrate, 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 use fig.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 on codec and extra_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.