1 class HookeCurve(object):
3 def __init__(self,path):
8 def identify(self, drivers):
10 identifies a curve and returns the corresponding object
12 for driver in drivers:
13 tempcurve=driver(self.path)
15 #bring on all the driver, with his load of methods etc.
16 #so we can access the whole of it.
21 print 'Not a recognizable curve format.'
27 Base class for file format drivers.
37 This method must read the file and return True if the filetype can be managed by the driver, False if not.
43 This method must close all the open files of the driver, explicitly.
47 def default_plots(self):
48 dummy_default=PlotObject()
49 dummy_default.vectors.append([[[0]],[[0]]])
50 return [dummy_default]
53 class PlotObject(object):
65 self.vectors is a multidimensional array:
71 2 curves in a x,y plot are:
72 [[[x1],[y1]],[[x2],[y2]]]
75 [[[1,2,3,4],[10,20,30,40]],[[3,6,9,12],[30,60,90,120]]]
76 x1 = self.vectors[0][0]
77 y1 = self.vectors[0][1]
78 x2 = self.vectors[1][0]
79 y2 = self.vectors[1][1]
84 self.units is simpler. for each plot with N axes (x,y,z...) only N labels
85 can be made, regardless of the number of superimposed plots
86 so units for the double plot above is: [unitx, unity]
93 xaxes and yaxes directions. 0,0 means the common +X=right, +Y=top directions
101 styles: defines what is the style of the current plots. If undefined or None, it is line plot.
102 If an element of the list is 'scatter', the corresponding dataset
103 is drawn with scattered points and not a continuous line.
108 colors: define what is the colour of the current plots
112 def add_set(self,x,y):
114 Adds an x,y data set to the vectors.
116 self.vectors.append([])
117 self.vectors[-1].append(x)
118 self.vectors[-1].append(y)
121 def remove_set(self,whichset):
125 waste=self.vectors.pop(whichset)
128 def normalize_vectors(self):
130 Trims the vector lengths as to be equal in a plot.
133 for index in range(0,len(self.vectors)):
134 vectors_to_plot=self.vectors[index]
135 lengths=[len(vector) for vector in vectors_to_plot]
136 if min(lengths) != max(lengths):
137 for indexplot in range(0,len(vectors_to_plot)):
138 self.vectors[index][indexplot] = self.vectors[index][indexplot][0:min(lengths)]