-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhistograms.py
55 lines (41 loc) · 1.38 KB
/
histograms.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import unpickle as up
import matplotlib.pyplot as plt
import numpy as np
import collections
folder = "D:\Pickled_Data_2\\"
def collect_months(ships):
result = []
for ship in ships:
result.append(ship.month)
return result
def collect_speeds(ships,depth):
result = []
for ship in ships:
result.append(ship.sound_speed[depth])
return result
def month_histogram(ships):
months = collect_months(ships)
count = collections.Counter(months)
print(count)
plt.bar(list(count.keys()),count.values(),edgecolor="black")
plt.xlabel("Month")
plt.ylabel("Count")
plt.savefig("D:\\Month_Histogram.png")
#plt.show()
plt.close()
def speed_histogram(ships):
for depth in range(0,3):
speeds = collect_speeds(ships,depth)
count = collections.Counter(speeds)
print(count)
print(len(list(count.keys())))
plt.bar(list(count.keys()),count.values(),edgecolor="black",width=0.5)
plt.xlabel("Sound Speed at Depth: {}".format(depth*100))
plt.ylabel("Count")
plt.savefig("D:\\Speed_Histogram_{}.png".format(depth*100))
plt.close()
def histograms():
ships = up.unpickle_ships(folder)
month_histogram(ships)
speed_histogram(ships)
histograms()