1 '''
2 Created on 07.04.2011
3
4 @author: tohe
5 '''
6 import numpy
7 from os import path
8 from time import strftime
9 import matplotlib.pyplot as pylab
10
11
12
13 from dsc_suite.tools.toolpaths import FOLDER_FOR_DATA, FOLDER_FOR_PLOTS
14
16 '''plot_histogram
17 plots the histogram of the data
18 axis limits must be edited individually
19
20 just works with SUM files
21
22 entry format: list of dictionaries with the following keys:
23 ['benchmark', 'data structure', 'filename',
24 'samples', 'depth', 'cost criteria',
25 'mean value', 'standard deviation']
26 create_png:
27 True --> return value filename of png file
28 False --> opens interactive mode of matplotlib
29 '''
30
31 labels = parameter["labels"]
32 sizes = parameter["sizes"]
33 axes = parameter["axes"]
34
35
36 title = labels["title"]
37 legend_position = labels["legend-position"]
38 legend_title = labels["legend-title"]
39 legend_parameter = labels["legend-parameter"]
40 xlabel = labels["x-label"]
41 ylabel = labels["y-label"]
42
43
44 width = sizes["dimensions"]["width"]
45 length = sizes["dimensions"]["length"]
46 left = sizes["margins"]["left"]
47 right = sizes["margins"]["right"]
48 top = sizes["margins"]["top"]
49 bottom = sizes["margins"]["bottom"]
50
51
52
53 if axes["x-axe"]["xmin"] == "auto":
54 xmin = 0.0
55 else:
56 xmin = axes["x-axe"]["xmin"]
57 if axes["x-axe"]["xmax"] == "auto":
58 xmax = 0.0
59 else:
60 xmax = axes["x-axe"]["xmin"]
61 if axes["y-axe"]["ymin"] == "auto":
62 ymin = 0.0
63 else:
64 ymin = axes["y-axe"]["ymin"]
65 if axes["y-axe"]["ymax"] == "auto":
66 ymax = 0.0
67 else:
68 ymax = axes["y-axe"]["ymax"]
69 num_bins = 50
70
71 pylab.figure(1,(length,width))
72 pylab.subplots_adjust(left,bottom,right,top)
73 pylab.ticklabel_format(style = "sci", scilimits = (-2,5))
74
75 arrays = []
76 legend_labels = []
77
78 for file in filenames:
79 array = numpy.load(FOLDER_FOR_DATA+"/"+file)
80 arrays.append(array)
81 try:
82 legend_labels.append(information[file][legend_parameter])
83 except:
84 try:
85 legend_labels.append(information[file][legend_parameter.replace(" ", "_")])
86 except:
87 for key in information[file]["cost_criteria"]:
88 try:
89 legend_labels.append(information[file]["cost_criteria"][key][legend_parameter])
90 except:
91 try:
92 legend_labels.append(information[file]["cost_criteria"][key][legend_parameter.replace(" ","_")])
93 except:
94 pass
95
96 if legend_labels != []:
97 for i in range(0,len(arrays),1):
98 ret = pylab.hist(arrays[i], bins=num_bins, label=legend_labels[i], histtype='step')
99 if numpy.amax(ret[0]) > xmax:
100 xmax = numpy.amax(ret[0])
101 if numpy.amax(ret[1]) > ymax:
102 ymax = numpy.amax(ret[1])
103 else:
104 for i in range(0,len(arrays),1):
105 ret = pylab.hist(arrays[i], bins=num_bins, histtype='step')
106 if numpy.amax(ret[1]) > xmax:
107 xmax = numpy.amax(ret[1])
108 if numpy.amax(ret[0]) > ymax:
109 ymax = numpy.amax(ret[0])
110
111 pylab.suptitle(title)
112
113 if legend_labels != []:
114 pylab.legend(title = legend_title, loc=legend_position)
115
116 pylab.xlabel(xlabel)
117 pylab.ylabel(ylabel)
118
119 pylab.axis([xmin, xmax, ymin, ymax])
120 pylab.grid(True, which='both')
121
122 if create_png:
123 i = 1
124 filename = 'Histogram %s %02i.png' % (strftime("%Y-%m-%d %H%M%S"), i)
125 while path.exists(FOLDER_FOR_PLOTS + '/' + filename):
126 i += 1
127 filename = 'Histogram %s %02i.png' % (strftime("%Y-%m-%d %H%M%S"), i)
128 pylab.savefig(FOLDER_FOR_PLOTS + '/' + filename)
129 pylab.close()
130 return filename
131 pylab.show()
132