3 class HookeCurve(object):
5 def __init__(self, path):
6 #the data dictionary contains: {name of data: list of data sets [{[x], [y]}]
11 self.name = os.path.basename(path)
15 def add_data(self, name, x, y, color=None, result=None, style=None, visible=True):
16 data = {'x': x, 'y': y, 'color': color, 'result': result, 'style': style, 'visible': visible}
17 if self.data.has_key(name):
18 #get the existing list of xydata
19 list_data = self.data[name]
21 #we need a new list of xydata
23 #append the xydata to the list
24 list_data.append(data)
25 #append or change the corresponding dictionary entry
26 self.data[name] = list_data
28 #def add_result(self, name, index, result):
29 #if self.data.has_key(name):
30 ##get the existing list of xydata
31 #list_data = self.data[name][index]
32 #list_data['result'] = result
34 def delete_data(self, name):
35 if self.data.has_key(name):
38 def identify(self, drivers):
40 identifies a curve and returns the corresponding object
42 for driver in drivers:
43 current_driver = driver(self.filename)
44 if current_driver.is_me():
45 #bring on all the driver, with its load of methods etc.
46 #so we can access the whole of it.
47 self.driver = current_driver
49 print 'Not a recognizable curve format: ', self.path
52 def set_data(self, name, x, y, color=None, result=None, style=None, visible=True):
53 data = {'x': x, 'y': y, 'color': color, 'result': result, 'style': style, 'visible': visible}
54 #append the xydata to the list
56 #append or change the corresponding dictionary entry
57 self.data[name] = list_data
62 Base class for file format drivers.
72 This method must read the file and return True if the filetype can be managed by the driver, False if not.
78 This method must close all the open files of the driver, explicitly.
82 def default_plots(self):
83 dummy_default = PlotObject()
84 dummy_default.vectors.append([[[0]],[[0]]])
85 return [dummy_default]
88 class PlotObject(object):
100 self.vectors is a multidimensional array:
101 self.vectors[0]=plot1
102 self.vectors[1]=plot2
103 self.vectors[2]=plot3
106 2 curves in a x,y plot are:
107 [[[x1],[y1]],[[x2],[y2]]]
110 [[[1,2,3,4],[10,20,30,40]],[[3,6,9,12],[30,60,90,120]]]
111 x1 = self.vectors[0][0]
112 y1 = self.vectors[0][1]
113 x2 = self.vectors[1][0]
114 y2 = self.vectors[1][1]
119 self.units is simpler. for each plot with N axes (x,y,z...) only N labels
120 can be made, regardless of the number of superimposed plots
121 so units for the double plot above is: [unitx, unity]
128 xaxes and yaxes directions. 0, 0 means the common +X=right, +Y=top directions
134 self.title = '' #title
137 styles: defines what is the style of the current plots. If undefined or None, it is line plot.
138 If an element of the list is 'scatter', the corresponding dataset
139 is drawn with scattered points and not a continuous line.
144 colors: define what is the colour of the current plots
148 def add_set(self, x, y):
150 Adds an x, y data set to the vectors.
152 self.vectors.append([])
153 self.vectors[-1].append(x)
154 self.vectors[-1].append(y)
156 def remove_set(self, whichset):
160 #TODO: do we need 'waste' here?
161 waste = self.vectors.pop(whichset)
163 def normalize_vectors(self):
165 Trims the vector lengths as to be equal in a plot.
167 for index in range(0,len(self.vectors)):
168 vectors_to_plot=self.vectors[index]
169 lengths=[len(vector) for vector in vectors_to_plot]
170 if min(lengths) != max(lengths):
171 for indexplot in range(0,len(vectors_to_plot)):
172 self.vectors[index][indexplot] = self.vectors[index][indexplot][0:min(lengths)]