-
-
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 all 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,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): | ||
|
@@ -22,7 +22,8 @@ def derivs(state, t): | |
del_ = state[2]-state[0] | ||
den1 = (M1+M2)*L1 - M2*L1*cos(del_)*cos(del_) | ||
dydx[1] = (M2*L1*state[1]*state[1]*sin(del_)*cos(del_) | ||
+ M2*G*sin(state[2])*cos(del_) + M2*L2*state[3]*state[3]*sin(del_) | ||
+ M2*G*sin(state[2])*cos(del_) | ||
+ M2*L2*state[3]*state[3]*sin(del_) | ||
- (M1+M2)*G*sin(state[0]))/den1 | ||
|
||
dydx[2] = state[3] | ||
|
@@ -46,19 +47,17 @@ def derivs(state, t): | |
th2 = -10.0 | ||
w2 = 0.0 | ||
|
||
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 |
||
rad = pi/180 | ||
|
||
# initial state | ||
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 +67,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() |
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.
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 comment
The 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?