aboutsummaryrefslogtreecommitdiff
path: root/qolab/data/trace.py
blob: 488bcfda2e544ad05bc7bd687ce73d55d6b5d975 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class Trace:
    def __init__(self, descrStr):
        self.descr = descrStr
        self.values = None
        self.label = None
        self.unit = None
        self.attributes = {}

    def plot(self):
        import matplotlib.pyplot as plt
        plt.plot(self.values, label=self.descr)
        plt.legend()
        

class TraceXY:
    def __init__(self, descrStr):
        self.descr = descrStr
        self.x = Trace('x_values')
        self.y = Trace('y_values')

    def plot(self):
        import matplotlib.pyplot as plt
        plt.plot(self.x.values, self.y.values, label=self.descr)
        plt.legend()
        plt.xlabel(self.x.label)
        
class TraceSetSameX:
    def __init__(self, descrStr):
        self.descr = descrStr
        self.x = Trace('x_values')
        self.traces={}

    def addTrace(self, tr):
        if len(self.traces) == 0:
            self.x = tr.x
        trY = tr.y
        self.traces[tr.descr]=trY
        
    def plot(self):
        import matplotlib.pyplot as plt
        for k, tr in self.traces.items():
            plt.plot(self.x.values, tr.values, label=tr.descr)
        plt.xlabel(self.x.label)
        plt.legend()

    def items(self):
        return (self.traces.items())

    def keys(self):
        return (self.traces.keys())

    def getTrace(self, name):
        tr = TraceXY(name)
        tr.x = self.x
        tr.y = self.traces[name]
        return (tr)