-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Pep8ify examples #3425
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
Pep8ify examples #3425
Changes from 5 commits
99d3477
1c37e78
d0d9632
75b465c
9c2724c
64dfd4a
1d8d5c5
4a0f5f4
1171a96
dbd543e
ccb8efe
d65f921
9debab4
6636c30
47fbcd5
706f57d
9bcd5d3
f71c40d
a1cda13
23413a8
43c4c50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,9 @@ | |
import matplotlib.pyplot as plt | ||
import matplotlib.animation as animation | ||
|
||
|
||
def update_line(num, data, line): | ||
line.set_data(data[...,:num]) | ||
line.set_data(data[..., :num]) | ||
return line, | ||
|
||
# Set up formatting for the movie files | ||
|
@@ -25,7 +26,7 @@ def update_line(num, data, line): | |
plt.xlabel('x') | ||
plt.title('test') | ||
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l), | ||
interval=50, blit=True) | ||
interval=50, blit=True) | ||
line_ani.save('lines.mp4', writer=writer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and yet, here is an example that goes ahead and "saves" an animation... wtf? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a problem? The examples are not run by travis-ci, are they? |
||
|
||
fig2 = plt.figure() | ||
|
@@ -38,5 +39,5 @@ def update_line(num, data, line): | |
ims.append((plt.pcolor(x, y, base + add, norm=plt.Normalize(0, 30)),)) | ||
|
||
im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000, | ||
blit=True) | ||
blit=True) | ||
im_ani.save('im.mp4', writer=writer) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
import scipy.stats as ss | ||
from matplotlib.animation import FuncAnimation | ||
|
||
|
||
class UpdateDist(object): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since when did we have to start putting a blank line between a class declaration and its init? |
||
def __init__(self, ax, prob=0.5): | ||
self.success = 0 | ||
self.prob = prob | ||
|
@@ -43,5 +45,5 @@ def __call__(self, i): | |
ax = fig.add_subplot(1, 1, 1) | ||
ud = UpdateDist(ax, prob=0.7) | ||
anim = FuncAnimation(fig, ud, frames=np.arange(100), init_func=ud.init, | ||
interval=100, blit=True) | ||
interval=100, blit=True) | ||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,11 @@ | |
import scipy.integrate as integrate | ||
import matplotlib.animation as animation | ||
|
||
G = 9.8 # acceleration due to gravity, in m/s^2 | ||
L1 = 1.0 # length of pendulum 1 in m | ||
L2 = 1.0 # length of pendulum 2 in m | ||
M1 = 1.0 # mass of pendulum 1 in kg | ||
M2 = 1.0 # mass of pendulum 2 in kg | ||
G = 9.8 # acceleration due to gravity, in m/s^2 | ||
L1 = 1.0 # length of pendulum 1 in m | ||
L2 = 1.0 # length of pendulum 2 in m | ||
M1 = 1.0 # mass of pendulum 1 in kg | ||
M2 = 1.0 # mass of pendulum 2 in kg | ||
|
||
|
||
def derivs(state, t): | ||
|
@@ -46,19 +46,17 @@ def derivs(state, t): | |
th2 = -10.0 | ||
w2 = 0.0 | ||
|
||
rad = pi/180 | ||
|
||
# initial state | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused var |
||
state = np.array([th1, w1, th2, w2])*pi/180. | ||
state = np.radians([th1, w1, th2, w2]) | ||
|
||
# integrate your ODE using scipy.integrate. | ||
y = integrate.odeint(derivs, state, t) | ||
|
||
x1 = L1*sin(y[:,0]) | ||
y1 = -L1*cos(y[:,0]) | ||
x1 = L1*sin(y[:, 0]) | ||
y1 = -L1*cos(y[:, 0]) | ||
|
||
x2 = L2*sin(y[:,2]) + x1 | ||
y2 = -L2*cos(y[:,2]) + y1 | ||
x2 = L2*sin(y[:, 2]) + x1 | ||
y2 = -L2*cos(y[:, 2]) + y1 | ||
|
||
fig = plt.figure() | ||
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 2)) | ||
|
@@ -68,21 +66,23 @@ def derivs(state, t): | |
time_template = 'time = %.1fs' | ||
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes) | ||
|
||
|
||
def init(): | ||
line.set_data([], []) | ||
time_text.set_text('') | ||
return line, time_text | ||
|
||
|
||
def animate(i): | ||
thisx = [0, x1[i], x2[i]] | ||
thisy = [0, y1[i], y2[i]] | ||
|
||
line.set_data(thisx, thisy) | ||
time_text.set_text(time_template%(i*dt)) | ||
time_text.set_text(time_template % (i*dt)) | ||
return line, time_text | ||
|
||
ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y)), | ||
interval=25, blit=True, init_func=init) | ||
interval=25, blit=True, init_func=init) | ||
|
||
#ani.save('double_pendulum.mp4', fps=15) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here is a commented out save call that didn't get a space. Seems to me like whatever tool was used wasn't consistent (but I prefer this style) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be a bug in autopep8. The pep8 tool still detects the edit:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this does not conform to pep8 (http://legacy.python.org/dev/peps/pep-0008/#block-comments) but this is not a problem since we ignore E265. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have some issues with the comment related white-space rules #2930 .... |
||
plt.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
fig = plt.figure() | ||
|
||
|
||
def f(x, y): | ||
return np.sin(x) + np.cos(y) | ||
|
||
|
@@ -24,9 +25,9 @@ def f(x, y): | |
ims.append([im]) | ||
|
||
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True, | ||
repeat_delay=1000) | ||
repeat_delay=1000) | ||
|
||
#ani.save('dynamic_images.mp4') | ||
# ani.save('dynamic_images.mp4') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another commented out animation save call. |
||
|
||
|
||
plt.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is supposed to be a commented out piece of code, so it probably shouldn't have a space here. This is an odd one because we need to show people how one would save an animation, without actually doing it.