本文整理汇总了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();
示例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()
示例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()