Skip to content

Commit 73c2de0

Browse files
author
Jonathan Rocher
committed
Moved files to a parallelcomputing folder. Added demo code for xmlrpc, matplotlib.
1 parent 07ef820 commit 73c2de0

File tree

10 files changed

+2797476
-0
lines changed

10 files changed

+2797476
-0
lines changed

matplotlib/animation_demo.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
""" Demo of a timer and an animation using matplotlib: crashes on WX but work
2+
with the QT backend.
3+
"""
4+
5+
from matplotlib import pyplot as plt
6+
7+
from datetime import datetime
8+
fig = plt.figure()
9+
ax = fig.add_subplot(1, 1, 1)
10+
11+
def updateTime(axes):
12+
axes.set_title(datetime.now())
13+
axes.figure.canvas.draw()
14+
15+
# Specifying interval=100 is enough except for QT backend
16+
timer = fig.canvas.new_timer(interval=100)
17+
# Add a call back to the function above. The callback can also be give a class
18+
# with a __call__ method. See animation_demo2.
19+
timer.add_callback(updateTime, ax)
20+
timer.interval = 100 # Work around bug in QT timer
21+
22+
timer.start()
23+
plt.show()

matplotlib/animation_demo2.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
""" Demo 2 of a timer and an animation using matplotlib: this time the
2+
Note: crashes on WX but works with the QT backend.
3+
"""
4+
5+
fig = plt.figure()
6+
ax = fig.add_subplot(1, 1, 1)
7+
x = np.linspace(0, 20)
8+
y = 0.5 * x * x
9+
line, = ax.plot(x, y)
10+
11+
# The class only takes a line object as a parameter. All
12+
# of the needed information is obtained from the object itself.
13+
class updatingLine(object):
14+
def __init__(self, line):
15+
self._line = line
16+
self._xdata = line.get_xdata()
17+
self._ydata = line.get_ydata()
18+
self.counter = 0
19+
self.canvas = line.figure.canvas
20+
21+
def __call__(self):
22+
self._line.set_data(self._xdata[:self.counter],
23+
self._ydata[:self.counter])
24+
self.canvas.draw()
25+
self.counter = (self.counter + 1) % self._xdata.size
26+
27+
timer = fig.canvas.new_timer(interval=100)
28+
timer.add_callback(updatingLine(line))
29+
timer.start()

matplotlib/animation_demo3.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import numpy as np
2+
from matplotlib.animation import FuncAnimation
3+
import matplotlib.pyplot as plt
4+
5+
t = np.linspace(0, 10, 500)
6+
x = np.exp(-0.5 * t) * np.sin(2 * np.pi * t)
7+
fig = plt.figure()
8+
ax = fig.add_subplot(1, 1, 1)
9+
line, = plt.plot(t, x)
10+
11+
def update_line(frame, line, t, x):
12+
line.set_data(t[:frame], x[:frame])
13+
14+
anim = FuncAnimation(fig, update_line, fargs=(line, t, x), interval=50,
15+
frames=t.size)
16+
plt.show()

0 commit comments

Comments
 (0)