Moved hooke.libhookecurve -> hooke.curve and rewrote HookeCurve -> Curve class.
[hooke.git] / hooke / ui / gui / plot.py
1 class PlotObject(object):
2
3     def __init__(self):
4
5         '''
6         the plot destination
7         0=top
8         1=bottom
9         '''
10         self.destination=0
11
12         '''
13         self.vectors is a multidimensional array:
14         self.vectors[0]=plot1
15         self.vectors[1]=plot2
16         self.vectors[2]=plot3
17         etc.
18
19         2 curves in a x,y plot are:
20         [[[x1],[y1]],[[x2],[y2]]]
21         for example:
22             x1          y1              x2         y2
23         [[[1,2,3,4],[10,20,30,40]],[[3,6,9,12],[30,60,90,120]]]
24         x1 = self.vectors[0][0]
25         y1 = self.vectors[0][1]
26         x2 = self.vectors[1][0]
27         y2 = self.vectors[1][1]
28         '''
29         self.vectors=[]
30
31         '''
32         self.units is simpler. for each plot with N axes (x,y,z...) only N labels
33         can be made, regardless of the number of superimposed plots
34         so units for the double plot above is: [unitx, unity]
35
36         units are strings
37         '''
38         self.units=['', '']
39
40         '''
41         xaxes and yaxes directions. 0, 0 means the common +X=right, +Y=top directions
42         '''
43         self.xaxes = 0
44         self.yaxes = 0
45
46         self.filename = ''
47         self.title = '' #title
48
49         '''
50         styles: defines what is the style of the current plots. If undefined or None, it is line plot.
51         If an element of the list is 'scatter', the corresponding dataset
52         is drawn with scattered points and not a continuous line.
53         '''
54         self.styles = []
55
56         '''
57         colors: define what is the colour of the current plots
58         '''
59         self.colors = []
60
61     def add_set(self, x, y):
62         '''
63         Adds an x, y data set to the vectors.
64         '''
65         self.vectors.append([])
66         self.vectors[-1].append(x)
67         self.vectors[-1].append(y)
68
69     def remove_set(self, whichset):
70         '''
71         Removes a set
72         '''
73         #TODO: do we need 'waste' here?
74         waste = self.vectors.pop(whichset)
75
76     def normalize_vectors(self):
77         '''
78         Trims the vector lengths as to be equal in a plot.
79         '''
80         for index in range(0,len(self.vectors)):
81             vectors_to_plot=self.vectors[index]
82             lengths=[len(vector) for vector in vectors_to_plot]
83             if min(lengths) != max(lengths):
84                 for indexplot in range(0,len(vectors_to_plot)):
85                     self.vectors[index][indexplot] = self.vectors[index][indexplot][0:min(lengths)]
86