/
plotMultiple.py
70 lines (58 loc) · 2.25 KB
/
plotMultiple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python
import os, numpy, sys
import plotMultipleConfig as config
import matplotlib.pyplot as plt
if __name__ == '__main__':
#Make sure it doesn't matter where things are executed from
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
os.chdir(PROJECT_DIR)
sys.path.append(PROJECT_DIR)
sys.path.append(os.path.join(PROJECT_DIR,'codelibs')) #add files in codelibs
from plotting import createEmptyPlottingArea, addDataWithErrorBarsToPlot
from file import loadTestFileWithBackgroundAndCalculateCountErr
def printHello():
print "Hello, I'm working!"
# See http://matplotlib.org/api/widgets_api.html for info on the widgets
# Selector example (also deals with key press): http://matplotlib.org/examples/widgets/rectangle_selector.htmls
class MainGuiController(object):
#Variables
def init(self, start, end):
(fig,axes) = createEmptyPlottingArea(config.test_x_axis_label, config.test_y_axis_label, x_majorticks=config.test_x_majorticks, x_minorticks=config.test_x_minorticks, x_length=end-start, fontsize = config.fontsize, figWidth=config.plotwidth, figHeight=config.plotheight)
self.fig = fig
self.axes = axes
self.start = start
self.end = end
def addPlot(self, data, label, fmt, start=-1, end=-1):
if start == -1:
start = self.start
if end == -1:
end = self.end
addDataWithErrorBarsToPlot(self.axes, data['Channel'][start:end], data['Count'][start:end], y_err=data['CountErr'][start:end], fmt=fmt, label=label)
def generateLegend(self):
self.axes.legend()
def setTitle(self, title):
self.axes.set_title(title)
def show(self):
plt.show()
#Callback functions
def addTestData(self):
pass
def deleteLastPlot(self):
pass
#Handle key presses
def handle_key(self, event):
if event.key in ['A', 'a']:
addTestData()
elif event.key in ['D', 'd']:
deleteLastPlot()
else:
print 'Detected keypress {0}, unknown command'.format(event.key)
if __name__ == '__main__':
mgc = MainGuiController()
mgc.init(config.datastart, config.dataend)
mgc.setTitle(config.title)
for (filepath, background, label, fmt) in config.inputfiles:
data = loadTestFileWithBackgroundAndCalculateCountErr(filepath, background, config.durationRegex, config.rescaletoduration)
mgc.addPlot(data, label, fmt)
mgc.generateLegend()
mgc.show()