Skip to content
This repository was archived by the owner on Sep 23, 2019. It is now read-only.

Commit 8ad0fca

Browse files
committed
Added new example with real-time multiple signals.
1 parent 27e2f56 commit 8ad0fca

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/realtime_multi.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Real-time example.
2+
3+
This example shows how a real-time visualizer of multiple digital signals can
4+
be written with Galry.
5+
6+
"""
7+
import numpy as np
8+
from galry import *
9+
10+
# initial values
11+
nsamples = 1000
12+
nplots = 10
13+
t = np.tile(np.linspace(-1., 1., nsamples), (nplots, 1))
14+
x = .01 * np.random.randn(nplots, nsamples) + np.linspace(-.75, .75, nplots)[:,np.newaxis]
15+
16+
# this function returns 10*nplots new values at each call
17+
def get_new_data():
18+
return .01 * np.random.randn(nplots, 10) + np.linspace(-.75, .75, nplots)[:,np.newaxis]
19+
20+
# this function updates the plot at each call
21+
def anim(fig, _):
22+
# append new data to the signal
23+
global x
24+
x = np.hstack((x[:,10:], get_new_data()))
25+
26+
# create the new 1000*nplots*2 position array with x, y values at each row
27+
position = np.vstack((t.flatten(), x.flatten())).T
28+
29+
# update the position of the plot
30+
fig.set_data(position=position)
31+
32+
# plot the signal
33+
plot(t, x)
34+
35+
# animate the plot: anim is called every 25 milliseconds
36+
animate(anim, dt=.025)
37+
38+
# show the figure
39+
show()

0 commit comments

Comments
 (0)