File: scope_mode_mpl_compare.py

package info (click to toggle)
wxmplot 0.9.58-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,052 kB
  • sloc: python: 10,085; makefile: 88; sh: 2
file content (29 lines) | stat: -rw-r--r-- 766 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# This could be comparable to
# https://matplotlib.org/stable/gallery/animation/strip_chart.html

import numpy as np
from wxmplot.interactive import plot, set_data_generator

class Scope:
    def __init__(self, nmax=50, dt=0.1):
        self.dt = dt
        self.nmax = nmax
        self.t = [0]
        self.y = [0]

    def update(self):
        if len(self.t) > self.nmax:
            self.t = [0]
            self.y = [0]

        p = np.random.rand()
        v = np.random.rand() if p < 0.15 else 0
        self.y.append(v)
        self.t.append(len(self.t))
        return [(np.array(self.t)*self.dt, np.array(self.y))]

NMAX, dt = 200, 0.05
scope = Scope(nmax=NMAX, dt=dt)

plot([0], [0], xmax=dt*NMAX)
set_data_generator(scope.update, polltime=int(1000*dt))