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