8000 Updated some examples [MEP12] by adasilva · Pull Request #6486 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Updated some examples [MEP12] #6486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
cleaned up animate_decay.py
  • Loading branch information
adasilva committed Jun 1, 2016
commit 12c4bb0dcff1a0c05065a3e791b63632e57a380c
20 changes: 16 additions & 4 deletions examples/animation/animate_decay.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
"""
Animated plot showing a decay process with updating x-scale.
"""

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation


def data_gen(t=0):
cnt = 0
while cnt < 1000:
cnt += 1
"""Generate data

Generates a decaying sine wave.
"""
count = 0
while count < 1000:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to a for count in range(1000): That is slightly more pythonic.

count += 1
t += 0.1
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)


def init():
"""Create a line

Returns a matplotlib line object.
"""
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(0, 10)
del xdata[:]
Expand All @@ -26,7 +38,7 @@ def init():


def run(data):
# update the data
"""Update the data, check and set axis scale"""
t, y = data
xdata.append(t)
ydata.append(y)
Expand Down
0