0

I would like to animate the data points which i receive from a DL model. I have followed the answer from here.

I had created my animated plot which satisfies my requirement. Kindly see the picture below, where it shows X axes labels Defect & No Defect start to raise from 0 and reach a maximum point.

I want two conditions to be met, after the animation completed,

  1. How can I annotate or display a message in the plot after the animation gets completed. (for eg : in my case I want to display maximum value - either defect or No defect in the plot based on the value)
  2. The picture shows below is for 1 iteration which ran for 100 frames. In the same way, i have another 30 iterations data where each of them should run for 100 frames using FuncAnimtaion, which produces animation graph for each iterations and display/annotate the maximum value at the end of iterations. I can give my 30 iterations one by one and produce results, but how one can achieve in code totally.

Picture at

Code

from matplotlib import animation
import matplotlib
from matplotlib import pyplot as plt
import numpy as np


def barlist(n): 
    
    # model detail
    b = n + 1
    c = X_test[0][:b].reshape((-1, b, X_test.shape[2])) # Input to model
    mod = model.predict_on_batch(c) # DL Model which takes input c
    pred = np.argmax(mod, axis=2) # Output a array

    St = np.count_nonzero(pred == 0)
    Rt = np.count_nonzero(pred)
    return [St, Rt] # for every frame St, Rt gets updated & animate plot

fig = plt.figure()
axes = plt.axes()
axes.set_ylim([0, 110])

x = np.arange(0,2)
my_xticks = ['Defect','No Defect']
plt.xticks(x, my_xticks)
barcollection = plt.bar(x,[0, 0], width= 0.3)

n = 100 #Number of frames

def animate(i):
    y = barlist(i)
    for i, b in enumerate(barcollection):
        b.set_height(y[i])
   



anim=animation.FuncAnimation(fig,animate,repeat=False,blit=False,frames=n,interval=50)
   
plt.show()
Mari
  • 698
  • 1
  • 8
  • 27
  • I reopened the question (seems no duplicate anymore), but I honestly have no idea what problem you face here. – ImportanceOfBeingErnest Jul 28 '19 at 17:02
  • @ImportanceOfBeingErnest I am not facing any problem, I am asking 1) `how can i annotate after completing 100 frames`. (print the highest value, say for example in my graph `Defect`has higher number. So annotate or print Defect is Maximum after completing the 100 frames. – Mari Jul 28 '19 at 18:17
  • @ImportanceOfBeingErnest 2 : As you can see above in my above code `c = X_test[0]...` `X_test is of shape (30, 100, 4)`. In the code above I have used only `X_test[0]` which means I used only `1st (100, 4)` and built a animation as per your answer. I can perform the same animation individually like input `X_test[1]` - animate, input `X_test[2]` - animate and so on....Instead I would like to do it in a single shot. Like if i give `X_test`, animate function should take `X_test[0]`, animate it, print which one is greater, then `X_test[1]` , animate it, print which one is greater & so on – Mari Jul 28 '19 at 18:26
  • @ImportanceOfBeingErnest I hope I have clarified my question correctly. If not please let me know. – Mari Jul 28 '19 at 19:20

0 Answers0