1 '''
2 Created on 07.04.2011
3
4 @author: tohe
5 '''
6
7 import numpy
8 from os import path
9 from time import strftime
10 import matplotlib.pyplot as pylab
11
12 from dsc_suite.analyses.standards import COLORS
13 from dsc_suite.tools.toolpaths import FOLDER_FOR_DATA, FOLDER_FOR_PLOTS
14
16 '''plot_2D_scatter_plot
17 plots a scatter plot of both cost criteria
18 third entry must contain different iteration values
19 --> used for color map
20
21 just works with SUM files
22 plots only the area of (0;1) for both axis
23
24 entry format: list of dictionaries with the following keys:
25 ['benchmark', 'data structure', 'filename',
26 'samples', 'depth', 'cost criteria',
27 'mean value', 'standard deviation']
28 create_png:
29 True --> return value filename of png file
30 False --> opens interactive mode of matplotlib
31 '''
32 if len(filenames) != 2 or len(filenames) != 3:
33
34 pass
35
36
37 labels = parameter["labels"]
38 sizes = parameter["sizes"]
39 axes = parameter["axes"]
40
41
42 title = labels["title"]
43 legend_position = labels["legend-position"]
44 legend_title = labels["legend-title"]
45 legend_parameter = labels["legend-parameter"]
46 xlabel = labels["x-label"]
47 ylabel = labels["y-label"]
48
49
50 width = sizes["dimensions"]["width"]
51 length = sizes["dimensions"]["length"]
52 left = sizes["margins"]["left"]
53 right = sizes["margins"]["right"]
54 top = sizes["margins"]["top"]
55 bottom = sizes["margins"]["bottom"]
56
57
58 if axes["x-axe"]["xmin"] == "auto":
59 xmin = 0.0
60 else:
61 xmin = axes["x-axe"]["xmin"]
62 if axes["x-axe"]["xmax"] == "auto":
63 xmax = 0.0
64 else:
65 xmax = axes["x-axe"]["xmin"]
66 if axes["y-axe"]["ymin"] == "auto":
67 ymin = 0.0
68 else:
69 ymin = axes["y-axe"]["ymin"]
70 if axes["y-axe"]["ymax"] == "auto":
71 ymax = 0.0
72 else:
73 ymax = axes["y-axe"]["ymax"]
74
75
76
77 pylab.figure(1,(length,width))
78 pylab.subplots_adjust(left,bottom,right,top)
79 pylab.ticklabel_format(style = "sci", scilimits = (-2,5))
80 color_array = None
81 print_dict = {}
82 norm_values = []
83 criteria = []
84 criteria_sort = []
85 print_array = []
86
87 for file in filenames:
88 dictionary = information[file]["cost_criteria"]
89 for key in dictionary.keys():
90 if str(dictionary[key]["filename"]) == str(file):
91 criteria.append(str(key))
92 print_dict.update({key : numpy.load(FOLDER_FOR_DATA+"/"+file)})
93 for crit in criteria:
94 sum_dict = information[file]["cost_criteria"]["SUM"]
95 for key in sum_dict:
96 if crit in key and "norm" in key:
97 norm_values.append(float(sum_dict[key]))
98 criteria_sort.append(crit)
99 print_array.append(print_dict[crit])
100
101 for i in range(0,len(print_array),1):
102 print_array[i] = print_array[i]/norm_values[i]
103 if i == 0:
104 if xmax < numpy.amax(print_array[i]):
105 xmax = numpy.amax(print_array[i])*1.01
106 elif i == 1:
107 if ymax < numpy.amax(print_array[i]):
108 ymax = numpy.amax(print_array[i])*1.01
109 else:
110 return
111 for crit in criteria_sort:
112 criteria.remove(crit)
113 if len(criteria) > 1:
114 return
115 for crit in criteria:
116 criteria_sort.append(crit)
117 color_array = print_dict[crit]
118
119
120 if len(filenames) == 3:
121 uniques = list(numpy.unique(color_array))
122 needed_colors = len(uniques)
123 quot = int(needed_colors/len(COLORS))+1
124 sep_uni = []
125 for i in range(0,needed_colors,quot):
126 sep_uni.append(uniques[i:(i+quot)])
127
128 for values in sep_uni:
129 xarray = []
130 yarray = []
131 color_code = COLORS[sep_uni.index(values)]
132 lab = ""
133 for uni in values:
134 if values.index(uni) == 0:
135 lab += str(round(uni,2))
136 elif values.index(uni) == len(values)-1:
137 lab += " - " + str(round(uni,2))
138 for i in range(0,len(color_array),1):
139 if uni == color_array[i]:
140 xarray.append(print_array[0][i])
141 yarray.append(print_array[1][i])
142 pylab.plot(xarray,yarray,"o", color=color_code, label = lab)
143
144 if len(filenames) == 2:
145 pylab.plot(print_array[0],print_array[1],",")
146
147 pylab.xlabel(xlabel)
148 pylab.ylabel(ylabel)
149
150 pylab.axis([xmin, xmax, ymin, ymax])
151
152 pylab.grid(True)
153
154 pylab.suptitle(title)
155
156 if len(filenames) == 3:
157 pylab.legend(title = legend_title, loc = legend_position)
158
159 if create_png:
160 i = 1
161 filename = '2D scatter plot %s %02i.png' % (strftime("%Y-%m-%d %H%M%S"), i)
162 while path.exists(FOLDER_FOR_PLOTS + '/' + filename):
163 i += 1
164 filename = '2D scatter plot %s %02i.png' % (strftime("%Y-%m-%d %H%M%S"), i)
165 pylab.savefig(FOLDER_FOR_PLOTS + '/' + filename)
166 pylab.close()
167 return filename
168 else:
169 pylab.show()
170