1 '''module cost_development
2
3 This module creates a plot of the found cost criteria over the iteration index.
4 The iteration index is the position in the data file.
5
6
7
8 @author: Tobias Heimpold
9 '''
10 import numpy
11 from os import path
12 from time import strftime
13 import matplotlib.pyplot as pylab
14
15
16
17 from dsc_suite.tools.toolpaths import FOLDER_FOR_DATA, FOLDER_FOR_PLOTS
18
19
21 '''plot_costdata_development
22 plots the cost_data in order of their index in file
23 runs only in beta version --> many changes must be hand made
24 interface to GUI not yet finished
25
26 create_png:
27 True --> return value filename of png file
28 False --> opens interactive mode of matplotlib
29 '''
30 print filenames
31 print information
32
33 labels = parameter["labels"]
34 sizes = parameter["sizes"]
35 axes = parameter["axes"]
36
37
38 title = labels["title"]
39 legend_position = labels["legend-position"]
40 legend_title = labels["legend-title"]
41 legend_parameter = labels["legend-parameter"]
42 xlabel = labels["x-label"]
43 ylabel = labels["y-label"]
44
45
46 width = sizes["dimensions"]["width"]
47 length = sizes["dimensions"]["length"]
48 left = sizes["margins"]["left"]
49 right = sizes["margins"]["right"]
50 top = sizes["margins"]["top"]
51 bottom = sizes["margins"]["bottom"]
52
53
54 if axes["x-axe"]["xmin"] == "auto":
55 xmin = 0.0
56 else:
57 xmin = axes["x-axe"]["xmin"]
58 if axes["x-axe"]["xmax"] == "auto":
59 xmax = 0.0
60 else:
61 xmax = axes["x-axe"]["xmin"]
62 if axes["y-axe"]["ymin"] == "auto":
63 ymin = 0.0
64 else:
65 ymin = axes["y-axe"]["ymin"]
66 if axes["y-axe"]["ymax"] == "auto":
67 ymax = 0.0
68 else:
69 ymax = axes["y-axe"]["ymax"]
70
71
72 pylab.figure(1,(length,width))
73 pylab.subplots_adjust(left,bottom,right,top)
74 pylab.ticklabel_format(style = "sci", scilimits = (-2,5))
75
76
77 yarrays = []
78 xarrays = []
79 legend_labels = []
80 highest_value = 0
81 longest_iteration = 0
82
83 for file in filenames:
84 load_array = numpy.load(FOLDER_FOR_DATA+"/"+file)
85 if len(load_array) > longest_iteration:
86 longest_iteration = len(load_array)
87 if max(load_array) > highest_value:
88 highest_value = max(load_array)
89 yarrays.append(load_array)
90 xarrays.append(range(0,len(load_array),1))
91 try:
92 legend_labels.append(information[file][legend_parameter])
93 except:
94 try:
95 legend_labels.append(information[file][legend_parameter.replace(" ", "_")])
96 except:
97 for key in information[file]["cost_criteria"]:
98 try:
99 legend_labels.append(information[file]["cost_criteria"][key][legend_parameter])
100 except:
101 try:
102 legend_labels.append(information[file]["cost_criteria"][key][legend_parameter.replace(" ","_")])
103 except:
104 pass
105 if xmax == 0:
106 xmax = longest_iteration
107 if ymax == 0:
108 ymax = highest_value
109
110 if len(legend_labels) > 0:
111 for i in range(0,len(yarrays),1):
112 pylab.plot(xarrays[i], yarrays[i], label = legend_labels[i])
113 else:
114 for i in range(0,len(yarrays),1):
115 pylab.plot(xarrays[i], yarrays[i])
116 pylab.xlabel(xlabel)
117 pylab.ylabel(ylabel)
118
119 pylab.axis([xmin,xmax,ymin,ymax])
120
121 pylab.suptitle(title)
122
123 if len(legend_labels) > 0:
124 pylab.legend(title = legend_title, loc=legend_position)
125
126 pylab.grid(True)
127
128 if create_png:
129 i = 1
130 filename = 'Cost development %s %02i.png' % (strftime("%Y-%m-%d %H%M%S"), i)
131 while path.exists(FOLDER_FOR_PLOTS + '/' + filename):
132 i += 1
133 filename = 'Cost development %s %02i.png' % (strftime("%Y-%m-%d %H%M%S"), i)
134 pylab.savefig(FOLDER_FOR_PLOTS + '/' + filename)
135 pylab.close()
136 return filename
137 else:
138 pylab.show()
139