本文整理汇总了Python中matplotlib.animation.FuncAnimation方法的典型用法代码示例。如果您正苦于以下问题:Python animation.FuncAnimation方法的具体用法?Python animation.FuncAnimation怎么用?Python animation.FuncAnimation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.animation
的用法示例。
在下文中一共展示了animation.FuncAnimation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_frames
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def save_frames(images, filename):
num_sequences, n_steps, w, h = images.shape
fig = plt.figure()
im = plt.imshow(combine_multiple_img(images[:, 0]), cmap=plt.cm.get_cmap('Greys'), interpolation='none')
plt.axis('image')
def updatefig(*args):
im.set_array(combine_multiple_img(images[:, args[0]]))
return im,
ani = animation.FuncAnimation(fig, updatefig, interval=500, frames=n_steps)
# Either avconv or ffmpeg need to be installed in the system to produce the videos!
try:
writer = animation.writers['avconv']
except KeyError:
writer = animation.writers['ffmpeg']
writer = writer(fps=3)
ani.save(filename, writer=writer)
plt.close(fig)
示例2: __init__
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def __init__(self, title, varieties, data_points,
anim=False, data_func=None, is_headless=False, legend_pos=4):
global anim_func
self.title = title
self.anim = anim
self.data_func = data_func
for i in varieties:
data_points = len(varieties[i]["data"])
break
self.draw_graph(data_points, varieties)
self.headless = is_headless
if anim and not self.headless:
anim_func = animation.FuncAnimation(self.fig,
self.update_plot,
frames=1000,
interval=500,
blit=False)
示例3: plot_quad_3d
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def plot_quad_3d(waypoints, get_world_frame):
"""
get_world_frame is a function which return the "next" world frame to be drawn
"""
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1], projection='3d')
ax.plot([], [], [], '-', c='cyan')[0]
ax.plot([], [], [], '-', c='red')[0]
ax.plot([], [], [], '-', c='blue', marker='o', markevery=2)[0]
ax.plot([], [], [], '.', c='red', markersize=4)[0]
ax.plot([], [], [], '.', c='blue', markersize=2)[0]
set_limit((-0.5,0.5), (-0.5,0.5), (-0.5,8))
plot_waypoints(waypoints)
an = animation.FuncAnimation(fig,
anim_callback,
fargs=(get_world_frame,),
init_func=None,
frames=400, interval=10, blit=False)
if len(sys.argv) > 1 and sys.argv[1] == 'save':
print "saving"
an.save('sim.gif', dpi=80, writer='imagemagick', fps=60)
else:
plt.show()
示例4: ts_anim
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def ts_anim():
# create a simple animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 100), ylim=(-1, 1))
Color = [ 1 ,0.498039, 0.313725];
line, = ax.plot([], [], '*',color = Color)
plt.xlabel("Time")
plt.ylabel("Measurement")
def init():
line.set_data([], [])
return line,
def animate(i):
x = np.linspace(0, i+1, i+1)
ts = 5*np.cos(x * 0.02 * np.pi) * np.sin(np.cos(x) * 0.02 * np.pi)
line.set_data(x, ts)
return line,
return animation.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=200, blit=True)
示例5: basic_animation
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def basic_animation(frames=100, interval=30):
"""Plot a basic sine wave with oscillating amplitude"""
fig = plt.figure()
ax = plt.axes(xlim=(0, 10), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
x = np.linspace(0, 10, 1000)
def init():
line.set_data([], [])
return line,
def animate(i):
y = np.cos(i * 0.02 * np.pi) * np.sin(x - i * 0.02 * np.pi)
line.set_data(x, y)
return line,
return animation.FuncAnimation(fig, animate, init_func=init,
frames=frames, interval=interval)
示例6: main
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def main():
global ax
numframes = 100
numpoints = 10
#color_data = np.random.random((numframes, numpoints))
data = np.random.random((numframes, 3, numpoints))*50
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
scat = ax.scatter(data[0,0,:], data[0,1,:], data[0,2,:], c='r', marker = 'o',alpha=0.5, s=100)
ani = animation.FuncAnimation(fig, update_plot, frames= range(numframes),
fargs=(data, scat))
plt.show()
# for i in range(100):
# scat._offsets3d = juggle_axes(data[i,0,:], data[i,1,:], data[i,2,:], 'z')
# for j in range(25):
# ax.text(data[i,0,:], data[i,1,:], data[i,2,:], '%s' % (j))
# fig.canvas.draw()
示例7: frames_to_gif
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def frames_to_gif(frames, prefix, save_dir, interval=50, fps=30):
"""
Convert frames to gif file
"""
assert len(frames) > 0
plt.figure(figsize=(frames[0].shape[1] / 72.,
frames[0].shape[0] / 72.), dpi=72)
patch = plt.imshow(frames[0])
plt.axis('off')
def animate(i):
patch.set_data(frames[i])
# TODO: interval should be 1000 / fps ?
anim = animation.FuncAnimation(
plt.gcf(), animate, frames=len(frames), interval=interval)
output_path = "{}/{}.gif".format(save_dir, prefix)
anim.save(output_path, writer='imagemagick', fps=fps)
示例8: show_animation
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def show_animation():
w = 1 << 9
h = 1 << 9
# w = 1920
# h = 1080
sl = SmoothLife(h, w)
sl.add_speckles()
sl.step()
fig = plt.figure()
# Nice color maps: viridis, plasma, gray, binary, seismic, gnuplot
im = plt.imshow(sl.field, animated=True,
cmap=plt.get_cmap("viridis"), aspect="equal")
def animate(*args):
im.set_array(sl.step())
return (im, )
ani = animation.FuncAnimation(fig, animate, interval=60, blit=True)
plt.show()
示例9: updateGraph
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def updateGraph(frame):
global fill_lines
global gpuy_list
global gpux_list
global gpuLine
global gpuAx
# Now draw the GPU usage
gpuy_list.popleft()
with open(gpuLoadFile, 'r') as gpuFile:
fileData = gpuFile.read()
# The GPU load is stored as a percentage * 10, e.g 256 = 25.6%
gpuy_list.append(int(fileData)/10)
gpuLine.set_data(gpux_list,gpuy_list)
fill_lines.remove()
fill_lines=gpuAx.fill_between(gpux_list,0,gpuy_list, facecolor='cyan', alpha=0.50)
return [gpuLine] + [fill_lines]
# Keep a reference to the FuncAnimation, so it does not get garbage collected
示例10: test_no_length_frames
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def test_no_length_frames():
fig, ax = plt.subplots()
line, = ax.plot([], [])
def init():
line.set_data([], [])
return line,
def animate(i):
x = np.linspace(0, 10, 100)
y = np.sin(x + i)
line.set_data(x, y)
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=iter(range(5)))
示例11: play_image
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def play_image(self):
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
left_cam = self.left_cam_readers['/davis/left/depth_image_raw']
first_view = left_cam[0]
first_view.acquire()
im = plt.imshow(first_view.img, animated=True)
#first_view.release()
def updatefig(frame_num, *args):
view = left_cam[frame_num]
view.acquire()
im.set_data(view.img)
return im,
ani = animation.FuncAnimation(fig, updatefig, frames=len(left_cam), blit=True)
ani.save("test.mp4")
plt.show()
示例12: on_click
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def on_click(self, event):
if event.inaxes == self.ax and self.running == False:
self.params = model.params_three()
self.coupling = np.zeros((9), float)
self.coupling[:6] = self.network.coupling_strength
length = self.system.N_output(self.CYCLES)
self.t = self.system.dt*np.arange(length)
self.trajectory = np.zeros((length, 3), float)
self.li_b.set_data(self.t, self.trajectory[:, 0])
self.li_g.set_data(self.t, self.trajectory[:, 1]-0.06)
self.li_r.set_data(self.t, self.trajectory[:, 2]-0.12)
ticks = np.asarray(self.t[::self.t.size/10], dtype=int)
self.ax.set_xticks(ticks)
self.ax.set_xticklabels(ticks)
self.ax.set_xlim(self.t[0], self.t[-1])
self.fig.canvas.draw()
self.anim = animation.FuncAnimation(self.fig, self.compute_step, init_func=self.init, frames=self.trajectory.shape[0], interval=0, blit=True, repeat=False)
self.running = True
示例13: on_click
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def on_click(self, event):
if event.inaxes == self.ax:
self.params = model.parameters_n()
self.g_inh = model.params['g_inh_0']
length = self.system.N_output(self.CYCLES)
self.t = self.system.dt*np.arange(length)
self.trajectory = np.zeros((length, self.num_osci), float)
for i in xrange(self.num_osci):
self.li[i].set_data(self.t, self.trajectory[:, i]-i*2.)
ticks = np.asarray(self.t[::self.t.size/10], dtype=int)
self.ax.set_xticks(ticks)
self.ax.set_xticklabels(ticks)
self.ax.set_xlim(self.t[0], self.t[-1])
self.fig.canvas.draw()
self.anim = animation.FuncAnimation(self.fig, self.compute_step, init_func=self.init, frames=self.trajectory.shape[0], interval=0, blit=True, repeat=False)
示例14: save_true_generated_frames
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def save_true_generated_frames(true, generated, filename):
num_sequences, n_steps, w, h = true.shape
# Background is 0, foreground as 1
true = np.copy(true[:16])
true[true > 0.1] = 1
# Set foreground be near 0.5
generated = generated * .5
# Background is 1, foreground is near 0.5
generated = 1 - generated[:16, :n_steps]
# Subtract true from generated so background is 1, true foreground is 0,
# and generated foreground is around 0.5
images = generated - true
# images[images > 0.5] = 1.
fig = plt.figure()
im = plt.imshow(combine_multiple_img(images[:, 0]), cmap=plt.cm.get_cmap('gist_heat'),
interpolation='none', vmin=0, vmax=1)
plt.axis('image')
def updatefig(*args):
im.set_array(combine_multiple_img(images[:, args[0]]))
return im,
ani = animation.FuncAnimation(fig, updatefig, interval=500, frames=n_steps)
try:
writer = animation.writers['avconv']
except KeyError:
writer = animation.writers['ffmpeg']
writer = writer(fps=3)
ani.save(filename, writer=writer)
plt.close(fig)
示例15: run
# 需要导入模块: from matplotlib import animation [as 别名]
# 或者: from matplotlib.animation import FuncAnimation [as 别名]
def run(self):
self._printLogs("Waiting for the robot to be in wake up position", "OKBLUE")
self.motion_service.wakeUp()
self.posture_service.goToPosture("StandInit", 0.1)
self.create_callbacks()
# self.startDLServer()
self._addTopic()
# graphplots
self._initialisePlot()
ani = animation.FuncAnimation(self.fig, self._animate, blit=False, interval=500 ,repeat=False)
# loop on, wait for events until manual interruption
try:
# while True:
# time.sleep(1)
# starting graph plot
plt.show() # blocking call hence no need for while(True)
except KeyboardInterrupt:
self._printLogs("Interrupted by user, shutting down", "FAIL")
self._cleanUp()
self._printLogs("Waiting for the robot to be in rest position", "FAIL")
# self.motion_service.rest()
sys.exit(0)
return