0% found this document useful (0 votes)
91 views

Animation Example Code - Animate - Decay - Py - Matplotlib 1.4

The document provides code for animating the decay of a sine wave using matplotlib. The code generates decaying sine wave data and animates plotting it using FuncAnimation to update the plot over time.

Uploaded by

Dhruv Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Animation Example Code - Animate - Decay - Py - Matplotlib 1.4

The document provides code for animating the decay of a sine wave using matplotlib. The code generates decaying sine wave data and animates plotting it using FuncAnimation to update the plot over time.

Uploaded by

Dhruv Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

11/19/2014

animation example code: animate_decay.py Matplotlib 1.4.2 documentation

home | examples | gallery | pyplot | docs Matplotlib Examples

previous | next | modules | index

animation Examples
Previous topic

animation Examples
Next topic

animation example code:


basic_example.py
This Page

Show Source
Quick search

Go
Enter search terms or a module, class
or function name.

Ads by Lyrics

Ad Options

animation example code:


animate_decay.py
[source code]
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def data_gen():
t = data_gen.t
cnt = 0
while cnt < 1000:
cnt+=1
t += 0.05
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
data_gen.t = 0
fig, ax = plt.subplots()
line, = ax.plot([], [], lw=2)
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(0, 5)
http://matplotlib.org/examples/animation/animate_decay.html

1/3

11/19/2014

animation example code: animate_decay.py Matplotlib 1.4.2 documentation

ax.grid()
xdata, ydata = [], []
def run(data):
# update the data
t,y = data
xdata.append(t)
ydata.append(y)
xmin, xmax = ax.get_xlim()
if t >= xmax:
ax.set_xlim(xmin, 2*xmax)
ax.figure.canvas.draw()
line.set_data(xdata, ydata)
return line,
ani = animation.FuncAnimation(fig, run, data_gen, blit=True, interval=10,
repeat=False)
plt.show()

Keywords: python, matplotlib, pylab, example, codex (see Search


examples)

Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the matplotlib development team; 2012 - 2014 The matplotlib
development team. Last updated on Oct 25, 2014. Created using Sphinx 1.3b2.

Ads by Lyrics

http://matplotlib.org/examples/animation/animate_decay.html

Ad Options

2/3

11/19/2014

animation example code: animate_decay.py Matplotlib 1.4.2 documentation

WebSpades Advertisement

http://matplotlib.org/examples/animation/animate_decay.html

3/3

You might also like