I have implemented an animation using the FuncAnimation method of matplotlib.animation.
There is no error in the code but I don't know where the problem really is!
Code:
def visualization(self):
fig = plt.figure()
def animation_frame(i):
print(i)
trimmed_dist = self.get_distributions(i, self.window_size + i)
# create labels
label_no = len(trimmed_dist)
labels = []
for index in range(label_no):
from_ = index * self.bucket_length
to_ = (index + 1) * self.bucket_length
label = '{:.2f} - {:.2f}'.format(from_, to_)
labels.append(label)
#create bar chart
colors = plt.cm.Dark2(range(label_no))
plt.xticks(rotation=90)
plt.bar(x=labels, height=trimmed_dist, color=colors)
frames_no = len(self.percentages) - self.window_size
print('frames_no:', frames_no)
animation = FuncAnimation(fig, animation_frame, frames=frames_no, interval=1000)
return animation
Output:
PS 1: The frame_no value is 877.
PS 2: I think the problem is with the return in the visualization method. So I have changed the code but it still doesn't work properly.
