Resolving conflicts
[satune.git] / src / analyzer / plot.py
1 import numpy as np
2 import matplotlib.pyplot as plt
3 IMAGEDIR = "report/pics/"
4
5 def generateHistograms(X, header):
6         global IMAGEDIR
7         for i, c in enumerate(X.T):
8                 plt.hist(c)
9                 plt.savefig(IMAGEDIR + header[i] + "-hist.pdf")
10                 plt.clf()
11
12 def generateScatterPlot(X, Y, header):
13         global IMAGEDIR
14         for i, feature in enumerate(X.T):
15                 values = np.unique(feature)
16                 values = np.sort(values)
17                 geomean = []
18                 for value in values:
19                         a =Y[np.where(feature == value)]
20                         a = np.array(map(lambda x :  x**(1.0/len(a)), a))
21                         geomean.append(a.prod())
22                 plt.plot(feature, Y, 'r.')
23                 for ii in range(0, len(geomean)-1):
24                         plt.plot(values[ii:ii + 2], geomean[ii:ii + 2], 'bo-')
25                 plt.savefig(IMAGEDIR + header[i] + "-scat.pdf")
26                 plt.clf()
27
28 def plot(data, header):
29         global IMAGEDIR
30         header=header[6:-1]
31         data = np.array(data)
32         X = data[:, 6:-4]
33         X[X==''] = '-1'
34         X = X.astype(np.float)
35         Y = data[:, -2]
36         Y = Y.astype(np.float)
37         generateHistograms(X, header)
38         generateScatterPlot(X, Y, header)
39
40         
41
42