-
Notifications
You must be signed in to change notification settings - Fork 0
/
matplotlib_wrapper.py
57 lines (41 loc) · 1.15 KB
/
matplotlib_wrapper.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
"""
This file is a wrapper for matplotlib library and is used to create graphs
"""
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import time
from constants import *
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
arr = list()
colors = ['b' for i in range(ARRAY_SIZE)]
"""
This function is used to animate the graph i.e for sorting arrays
"""
def animate(i):
# if arr == None:
# # our animation is completed
# time.sleep(5)
# plt.close()
# return
ids = [key for key, value in enumerate(arr)]
ax1.clear()
ax1.bar(ids, arr, color=colors)
"""
This method plots the graph
THis method runs in the main thread
"""
def plot(title):
ani = animation.FuncAnimation(fig, animate, interval=2)
print(title)
plt.title("{}\n".format(title))
plt.show()
"""
At every itteration of sorting this function is called to set the values
"""
def set_arr(arr_value, color_location=0, previos_color_location=0):
global arr, colors
arr = arr_value
colors[color_location] = "r"
if previos_color_location >= 0:
colors[previos_color_location] = "b"