1 '''
2 Created on 07.04.2011
3
4 @author: tohe
5 '''
6
7
9
10 """ Plot two-dimensional cost distribution.
11
12 entries ... filled with dictionaries --> format see below
13 grid_size ... resolution of the generated 2D histogram
14 create_png ... if True, a .png-file is created
15 (otherwise interactive use)
16
17 entry format: dictionary with the following keys:
18 ['benchmark', 'data structure', 'filename',
19 'samples', 'cost criteria']
20
21 Plots two different data sets against each other (e.g., same benchmark,
22 same data structure, but different cost criteria). Thus, it is possible
23 to visualize the correlation between this data.
24
25 """
26
27 labels = parameter["labels"]
28 sizes = parameter["sizes"]
29 axes = parameter["axes"]
30
31
32 title = labels["title"]
33 legend_position = labels["legend-position"]
34 legend_title = labels["legend-title"]
35 legend_parameter = labels["legend-parameter"]
36 xlabel = labels["x-label"]
37 ylabel = labels["y-label"]
38
39
40 width = sizes["dimensions"]["width"]
41 length = sizes["dimensions"]["length"]
42 left = sizes["margins"]["left"]
43 right = sizes["margins"]["right"]
44 top = sizes["margins"]["top"]
45 bottom = sizes["margins"]["bottom"]
46
47
48 if axes["x-axe"]["xmin"] == "auto":
49 xmin = 0.0
50 else:
51 xmin = axes["x-axe"]["xmin"]
52 if axes["x-axe"]["xmax"] == "auto":
53 xmax = 0.0
54 else:
55 xmax = axes["x-axe"]["xmin"]
56 if axes["y-axe"]["ymin"] == "auto":
57 ymin = 0.0
58 else:
59 ymin = axes["y-axe"]["ymin"]
60 if axes["y-axe"]["ymax"] == "auto":
61 ymax = 0.0
62 else:
63 ymax = axes["y-axe"]["ymax"]
64
65 if len(entries) != 2:
66 raise ValueError
67 horizontal_entry = entries[0]
68 vertical_entry = entries[1]
69 pylab.interactive(False)
70 horizontal = numpy.load(FOLDER_FOR_DATA + '/' + horizontal_entry['filename'])
71 vertical = numpy.load(FOLDER_FOR_DATA + '/' + vertical_entry['filename'])
72 H, xedges, yedges = histogram2d(horizontal,
73 vertical,
74 bins=grid_size,
75 normed=True)
76 extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
77 pylab.imshow(H, extent=extent, origin='lower')
78 pylab.axis('tight')
79
80 pylab.xlabel(xlabel)
81 pylab.ylabel(ylabel)
82
83 pylab.axis([xmin, xmax, ymin, ymax])
84
85 pylab.grid(True)
86
87 pylab.suptitle(title)
88
89 pylab.legend(title = legend_title, loc = legend_position)
90 if create_png:
91 i = 1
92 filename = '2D Cost Distribution %s %02i.png' % (strftime("%Y-%m-%d %H%M%S"), i)
93 while path.exists(FOLDER_FOR_PLOTS + '/' + filename):
94 i += 1
95 filename = '2D Cost Distribution %s %02i.png' % (strftime("%Y-%m-%d %H%M%S"), i)
96 pylab.savefig(FOLDER_FOR_PLOTS + '/' + filename)
97 pylab.close()
98 return filename
99 else:
100 pylab.show()
101 pass
102