-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistogram.py
36 lines (33 loc) · 1.37 KB
/
histogram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sys
if __name__ == "__main__":
colnames = ['Run', 'Iterations', 'Time', 'Mean value', 'Best value']
if len(sys.argv) == 1:
csv_name = "histogram_example.csv"
else:
csv_name = sys.argv[1]
frame = pd.read_csv(csv_name, skiprows=2,
names=colnames, usecols=[0, 1, 2, 3, 4])
# print(frame.head())
no_runs = int(frame.tail(1)['Run'])
best_val = min(frame['Best value'])
avg_runtime = sum(frame['Time'])/no_runs
# print(no_runs)
count, bins, ignored = plt.hist(frame['Best value'], 15, density=False)
# binplt = [(bins[i]+bins[i+1])/2 for i in range(len(bins)-1)]
# plt.plot(binplt, count, linewidth=2, color='r')
plt.title("Histogram of results, Average runtime: " + str(int(avg_runtime)) + " s" )
plt.xticks(bins,rotation=45)
plt.ylabel("Number of results in range")
plt.xlabel("Final best value")
plt.savefig('histogram_best.png',bbox_inches='tight')
plt.close()
count, bins, ignored = plt.hist(frame['Mean value'], 15, density=False)
plt.title("Histogram of results, Average runtime: " + str(int(avg_runtime)) + " s" )
plt.xticks(bins,rotation=45)
plt.ylabel("Number of results in range")
plt.xlabel("Final mean value")
plt.savefig('histogram_mean.png',bbox_inches='tight')
plt.close()