1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke. If not, see
17 # <http://www.gnu.org/licenses/>.
19 class PlotObject(object):
31 self.vectors is a multidimensional array:
37 2 curves in a x,y plot are:
38 [[[x1],[y1]],[[x2],[y2]]]
41 [[[1,2,3,4],[10,20,30,40]],[[3,6,9,12],[30,60,90,120]]]
42 x1 = self.vectors[0][0]
43 y1 = self.vectors[0][1]
44 x2 = self.vectors[1][0]
45 y2 = self.vectors[1][1]
50 self.units is simpler. for each plot with N axes (x,y,z...) only N labels
51 can be made, regardless of the number of superimposed plots
52 so units for the double plot above is: [unitx, unity]
59 xaxes and yaxes directions. 0, 0 means the common +X=right, +Y=top directions
65 self.title = '' #title
68 styles: defines what is the style of the current plots. If undefined or None, it is line plot.
69 If an element of the list is 'scatter', the corresponding dataset
70 is drawn with scattered points and not a continuous line.
75 colors: define what is the colour of the current plots
79 def add_set(self, x, y):
81 Adds an x, y data set to the vectors.
83 self.vectors.append([])
84 self.vectors[-1].append(x)
85 self.vectors[-1].append(y)
87 def remove_set(self, whichset):
91 #TODO: do we need 'waste' here?
92 waste = self.vectors.pop(whichset)
94 def normalize_vectors(self):
96 Trims the vector lengths as to be equal in a plot.
98 for index in range(0,len(self.vectors)):
99 vectors_to_plot=self.vectors[index]
100 lengths=[len(vector) for vector in vectors_to_plot]
101 if min(lengths) != max(lengths):
102 for indexplot in range(0,len(vectors_to_plot)):
103 self.vectors[index][indexplot] = self.vectors[index][indexplot][0:min(lengths)]