當前位置: 首頁>>代碼示例>>Python>>正文


Python animation.FFMpegWriter方法代碼示例

本文整理匯總了Python中matplotlib.animation.FFMpegWriter方法的典型用法代碼示例。如果您正苦於以下問題:Python animation.FFMpegWriter方法的具體用法?Python animation.FFMpegWriter怎麽用?Python animation.FFMpegWriter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在matplotlib.animation的用法示例。


在下文中一共展示了animation.FFMpegWriter方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: animate_pattern_recognition

# 需要導入模塊: from matplotlib import animation [as 別名]
# 或者: from matplotlib.animation import FFMpegWriter [as 別名]
def animate_pattern_recognition(syncpr_output_dynamic, image_height, image_width, animation_velocity = 75, title = None, save_movie = None):
        """!
        @brief Shows animation of pattern recognition process that has been preformed by the oscillatory network.
        
        @param[in] syncpr_output_dynamic (syncpr_dynamic): Output dynamic of a syncpr network.
        @param[in] image_height (uint): Height of the pattern (image_height * image_width should be equal to number of oscillators).
        @param[in] image_width (uint): Width of the pattern.
        @param[in] animation_velocity (uint): Interval between frames in milliseconds.
        @param[in] title (string): Title of the animation that is displayed on a figure if it is specified.
        @param[in] save_movie (string): If it is specified then animation will be stored to file that is specified in this parameter.
        
        """
        figure = plt.figure();
        
        def init_frame():
            return frame_generation(0);
        
        def frame_generation(index_dynamic):
            figure.clf();
            
            if (title is not None):
                figure.suptitle(title, fontsize = 26, fontweight = 'bold')
            
            ax1 = figure.add_subplot(121, projection='polar');
            ax2 = figure.add_subplot(122);
            
            dynamic = syncpr_output_dynamic.output[index_dynamic];
            
            artist1, = ax1.plot(dynamic, [1.0] * len(dynamic), marker = 'o', color = 'blue', ls = '');
            artist2 = syncpr_visualizer.__show_pattern(ax2, syncpr_output_dynamic, image_height, image_width, index_dynamic);
            
            return [ artist1, artist2 ];
        
        cluster_animation = animation.FuncAnimation(figure, frame_generation, len(syncpr_output_dynamic), interval = animation_velocity, init_func = init_frame, repeat_delay = 5000);

        if (save_movie is not None):
#             plt.rcParams['animation.ffmpeg_path'] = 'C:\\Users\\annoviko\\programs\\ffmpeg-win64-static\\bin\\ffmpeg.exe';
#             ffmpeg_writer = animation.FFMpegWriter();
#             cluster_animation.save(save_movie, writer = ffmpeg_writer, fps = 15);
            cluster_animation.save(save_movie, writer = 'ffmpeg', fps = 15, bitrate = 1500);
        else:
            plt.show(); 
開發者ID:annoviko,項目名稱:pyclustering,代碼行數:44,代碼來源:syncpr.py

示例2: animate_cluster_allocation

# 需要導入模塊: from matplotlib import animation [as 別名]
# 或者: from matplotlib.animation import FFMpegWriter [as 別名]
def animate_cluster_allocation(dataset, analyser, animation_velocity=75, tolerance=0.1, save_movie=None, title=None):
        """!
        @brief Shows animation of output dynamic (output of each oscillator) during simulation on a circle from [0; 2pi].
        
        @param[in] dataset (list): Input data that was used for processing by the network.
        @param[in] analyser (syncnet_analyser): Output dynamic analyser of the Sync network.
        @param[in] animation_velocity (uint): Interval between frames in milliseconds.
        @param[in] tolerance (double): Tolerance level that define maximal difference between phases of oscillators in one cluster.
        @param[in] save_movie (string): If it is specified then animation will be stored to file that is specified in this parameter.
        @param[in] title (string): If it is specified then title will be displayed on the animation plot.
        
        """
        
        figure = plt.figure()
        
        def init_frame():
            return frame_generation(0)
        
        def frame_generation(index_dynamic):
            figure.clf()
            if title is not None:
                figure.suptitle(title, fontsize = 26, fontweight = 'bold')
            
            ax1 = figure.add_subplot(121, projection='polar')
            
            clusters = analyser.allocate_clusters(eps = tolerance, iteration = index_dynamic)
            dynamic = analyser.output[index_dynamic]
            
            visualizer = cluster_visualizer(size_row = 2)
            visualizer.append_clusters(clusters, dataset)
            
            artist1, = ax1.plot(dynamic, [1.0] * len(dynamic), marker='o', color='blue', ls='')
            
            visualizer.show(figure, display = False)
            artist2 = figure.gca()
            
            return [ artist1, artist2 ]
        
        cluster_animation = animation.\
            FuncAnimation(figure, frame_generation, len(analyser), interval=animation_velocity, init_func=init_frame,
                          repeat_delay=5000)

        if save_movie is not None:
#             plt.rcParams['animation.ffmpeg_path'] = 'D:\\Program Files\\ffmpeg-3.3.1-win64-static\\bin\\ffmpeg.exe';
#             ffmpeg_writer = animation.FFMpegWriter(fps = 15);
#             cluster_animation.save(save_movie, writer = ffmpeg_writer);
            cluster_animation.save(save_movie, writer='ffmpeg', fps=15, bitrate=1500)
        else:
            plt.show() 
開發者ID:annoviko,項目名稱:pyclustering,代碼行數:51,代碼來源:syncnet.py

示例3: movie

# 需要導入模塊: from matplotlib import animation [as 別名]
# 或者: from matplotlib.animation import FFMpegWriter [as 別名]
def movie(image, filename=None, writer=None, fps=30):
    """
    Create and save a movie - mp4, gif, etc - of the various
    2D slices of a 3D ants image

    Try this:
        conda install -c conda-forge ffmpeg

    Example
    -------
    >>> import ants
    >>> mni = ants.image_read(ants.get_data('mni'))
    >>> ants.movie(mni, filename='~/desktop/movie.mp4')
    """

    image = image.pad_image()
    img_arr = image.numpy()

    minidx = max(0, np.where(image > 0)[0][0] - 5)
    maxidx = max(image.shape[0], np.where(image > 0)[0][-1] + 5)

    # Creare your figure and axes
    fig, ax = plt.subplots(1)

    im = ax.imshow(
        img_arr[minidx, :, :],
        animated=True,
        cmap="Greys_r",
        vmin=image.quantile(0.05),
        vmax=image.quantile(0.95),
    )

    ax.axis("off")

    def init():
        fig.axes("off")
        return (im,)

    def updatefig(frame):
        im.set_array(img_arr[frame, :, :])
        return (im,)

    ani = animation.FuncAnimation(
        fig,
        updatefig,
        frames=np.arange(minidx, maxidx),
        # init_func=init,
        interval=50,
        blit=True,
    )

    if writer is None:
        writer = animation.FFMpegWriter(fps=fps)

    if filename is not None:
        filename = os.path.expanduser(filename)
        ani.save(filename, writer=writer)
    else:
        plt.show() 
開發者ID:ANTsX,項目名稱:ANTsPy,代碼行數:61,代碼來源:plot.py


注:本文中的matplotlib.animation.FFMpegWriter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。