Python matplotlib.animation.FFMpegWriter() Examples
The following are 3
code examples of matplotlib.animation.FFMpegWriter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.animation
, or try the search function
.
Example #1
Source File: syncpr.py From pyclustering with GNU General Public License v3.0 | 4 votes |
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();
Example #2
Source File: syncnet.py From pyclustering with GNU General Public License v3.0 | 4 votes |
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()
Example #3
Source File: plot.py From ANTsPy with Apache License 2.0 | 4 votes |
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()