-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_maker.py
More file actions
55 lines (40 loc) · 1.83 KB
/
graph_maker.py
File metadata and controls
55 lines (40 loc) · 1.83 KB
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 matplotlib.pyplot as plt
def get_graph_figure(ammo_data, title, color):
figure = plt.figure(figsize=(6,4), dpi=80)
# fill arrays that define the point values for the broken line graph
# first point at 0 meters, max damage
distances = [0]
damages = [ammo_data[0][1]]
# fill other points
for i in range(len(ammo_data)):
distances.append(ammo_data[i][0])
damages.append(ammo_data[i][1])
# calculate high and low damage
highest_damage = int(damages[0])
lowest_damage = int(damages[-1])
# end graph at last point + 10x, same damage as last point
distances.append(distances[-1]+10)
damages.append(lowest_damage)
# create the broken line graph
plt.plot(distances, damages, '-', color=color)
for i, j in zip(distances[1:len(distances)-1], damages[1:len(damages)-1]):
plt.plot(i,j, 'D', color=color, markersize=4)
plt.text(i+0.1,j+0.7,str(j).format(i, j))
# defining y axis bounds, show lowest damage - 10 except if negative then zero, highest dmage +
graph_low = int(round(lowest_damage/5.0)*5.0)-10 if lowest_damage >= 20 else 0
plt.ylim(graph_low, highest_damage + 5)
plt.xlim(int(distances[0]), int(distances[-1]))
range_interval = 5 if distances[-1]<100 else 10
ax = plt.gca()
ax.set_xticks([i for i in range(0, int(distances[-1]))][::range_interval], minor=True)
ax.xaxis.grid(True, which = 'minor')
ax.xaxis.grid(True, which = 'major')
damage_interval = 5 if highest_damage<100 else 10
ax.set_yticks([i for i in range(graph_low, highest_damage + 3)][::damage_interval])
ax.yaxis.grid(True)
# add a title and axis labels
plt.title(title)
plt.xlabel('Distance (Meters)')
plt.ylabel('Damage')
plt.close()
return figure