Skip to content

Commit 64ed266

Browse files
committed
update scope mode example
1 parent d3b17a0 commit 64ed266

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

examples/scope_mode_mpl_compare.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# This could be comparable to
22
# https://matplotlib.org/stable/gallery/animation/strip_chart.html
33

4+
from random import random
45
import numpy as np
56
from wxmplot.interactive import plot, set_data_generator
67

7-
np.random.seed(19680801 // 10)
8-
98
class Scope:
109
def __init__(self, nmax=50, dt=0.1):
1110
self.dt = dt
1211
self.nmax = nmax
13-
self.t, self.y = [], []
14-
print(nmax, dt)
12+
self.tmax = dt*nmax
13+
self.t = []
14+
self.y = []
1515

1616
def update(self):
17-
if len(self.y) > self.nmax:
18-
self.t, self.y = [], []
19-
self.t.append(self.dt*len(self.y))
20-
p = np.random.rand()
21-
self.y.append(np.random.rand() if p < 0.15 else 0)
17+
n = len(self.y)
18+
if n > self.nmax:
19+
self.t, self.y, n = [0], [0], 1
20+
self.t.append(n*self.dt)
21+
self.y.append(random() if random() < 0.15 else 0)
2222
return [(self.t, self.y)]
2323

24-
NMAX, DT = 200, 0.05
25-
scope = Scope(nmax=NMAX, dt=DT)
24+
scope = Scope(nmax=200, dt=0.05)
25+
26+
plotter = plot([0], [0], xmax=scope.tmax, ymin=-0.05, ymax=1.05, drawstyle='steps-mid')
2627

27-
plot([0], [0], xmax=NMAX*DT)
28-
set_data_generator(scope.update)
28+
set_data_generator(scope.update, win=plotter.window)

0 commit comments

Comments
 (0)