'''
@author: Abdullah Sourav
The structure of script is based on @Sina's matplotlib animation tutorials ( https://bit.ly/2rfaxP3 )

The script is written to plot the locations of 7 tracked objects. By changing the number of data series [data, data2, data3,....] 
and output line [line, line2, line3,....], it can be edited to track different number of objects.

'''

import matplotlib.pyplot as plt
from matplotlib import animation
import pandas as pd
import numpy as np

# read data from csv file and drop the first row as it does not contain any location but the frame number
df = pd.read_csv("all_loc.csv")
df = df.drop(df.columns[0], 1)

# writer function initiation
Writer = animation.writers['ffmpeg']
writer = Writer(fps=14, metadata =dict(artist = "Me"), bitrate = -1)

# takes 7 data series and draw 7 lines
def update_line(num, data, line, data2, line2, data3, line3, data4, line4, data5, line5, data6, line6, data7, line7):
    line.set_data(data[...,:num])
    line2.set_data(data2[...,:num])
    line3.set_data(data3[...,:num])
    line4.set_data(data4[...,:num])
    line5.set_data(data5[...,:num])
    line6.set_data(data6[...,:num])
    line7.set_data(data7[...,:num])
    time_text.set_text("Frame: %.0f" % int(num))
    return line, line2, line3, line4, line5, line6, line7

# x, y locations of each object is converted into numpy array
data = np.array([df.iloc[:,0].values,df.iloc[:,1].values])
data2 = np.array([df.iloc[:,2].values,df.iloc[:,3].values])
data3 = np.array([df.iloc[:,4].values,df.iloc[:,5].values])
data4 = np.array([df.iloc[:,6].values,df.iloc[:,7].values])
data5 = np.array([df.iloc[:,8].values,df.iloc[:,9].values])
data6 = np.array([df.iloc[:,10].values,df.iloc[:,11].values])
data7 = np.array([df.iloc[:,12].values,df.iloc[:,13].values])

# figure and line properties
fig = plt.figure()
ax = fig.add_subplot(111)
l, = ax.plot([], [], 'r-', label = "Steer 1")
k= ax.plot([], [], 'c-', label = "Steer 2")[0]
f= ax.plot([], [], 'y-', label = "Steer 3")[0]
a= ax.plot([], [], 'm-', label = "Steer 4")[0]
b= ax.plot([], [], 'k-', label = "Steer 5")[0]
c= ax.plot([], [], 'b-', label = "Steer 6")[0]
d= ax.plot([], [], 'g-', label = "Steer 7")[0]

# place legend outside the plot
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

# hide the axes marker and ticks 
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)

# set the limits based on your data
ax.set_ylim(0,1500)
ax.set_xlim(0,1500)


# create the video and save into the local directories, change the "frames=500" to any desirable number of frames you want to plot 
time_text = ax.text(0.02,0.97,"", transform = ax.transAxes, fontsize = 11, color="green")
line_ani = animation.FuncAnimation(fig, update_line, frames=500, fargs = (data, l, data2, k, data3, f, 
                                                                          data4, a, data5,b, data6,c, data7, d))
plt.show()
line_ani.save("persp_500.mp4", writer= writer)

8dbc1806accd89efb05a4e44d4a7f26aea28192e
<mask token>


def update_line(num, data, line, data2, line2, data3, line3, data4, line4,
    data5, line5, data6, line6, data7, line7):
    line.set_data(data[..., :num])
    line2.set_data(data2[..., :num])
    line3.set_data(data3[..., :num])
    line4.set_data(data4[..., :num])
    line5.set_data(data5[..., :num])
    line6.set_data(data6[..., :num])
    line7.set_data(data7[..., :num])
    time_text.set_text('Frame: %.0f' % int(num))
    return line, line2, line3, line4, line5, line6, line7


<mask token>

<mask token>


def update_line(num, data, line, data2, line2, data3, line3, data4, line4,
    data5, line5, data6, line6, data7, line7):
    line.set_data(data[..., :num])
    line2.set_data(data2[..., :num])
    line3.set_data(data3[..., :num])
    line4.set_data(data4[..., :num])
    line5.set_data(data5[..., :num])
    line6.set_data(data6[..., :num])
    line7.set_data(data7[..., :num])
    time_text.set_text('Frame: %.0f' % int(num))
    return line, line2, line3, line4, line5, line6, line7


<mask token>
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.set_ylim(0, 1500)
ax.set_xlim(0, 1500)
<mask token>
plt.show()
line_ani.save('persp_500.mp4', writer=writer)

<mask token>
df = pd.read_csv('all_loc.csv')
df = df.drop(df.columns[0], 1)
Writer = animation.writers['ffmpeg']
writer = Writer(fps=14, metadata=dict(artist='Me'), bitrate=-1)


def update_line(num, data, line, data2, line2, data3, line3, data4, line4,
    data5, line5, data6, line6, data7, line7):
    line.set_data(data[..., :num])
    line2.set_data(data2[..., :num])
    line3.set_data(data3[..., :num])
    line4.set_data(data4[..., :num])
    line5.set_data(data5[..., :num])
    line6.set_data(data6[..., :num])
    line7.set_data(data7[..., :num])
    time_text.set_text('Frame: %.0f' % int(num))
    return line, line2, line3, line4, line5, line6, line7


data = np.array([df.iloc[:, 0].values, df.iloc[:, 1].values])
data2 = np.array([df.iloc[:, 2].values, df.iloc[:, 3].values])
data3 = np.array([df.iloc[:, 4].values, df.iloc[:, 5].values])
data4 = np.array([df.iloc[:, 6].values, df.iloc[:, 7].values])
data5 = np.array([df.iloc[:, 8].values, df.iloc[:, 9].values])
data6 = np.array([df.iloc[:, 10].values, df.iloc[:, 11].values])
data7 = np.array([df.iloc[:, 12].values, df.iloc[:, 13].values])
fig = plt.figure()
ax = fig.add_subplot(111)
l, = ax.plot([], [], 'r-', label='Steer 1')
k = ax.plot([], [], 'c-', label='Steer 2')[0]
f = ax.plot([], [], 'y-', label='Steer 3')[0]
a = ax.plot([], [], 'm-', label='Steer 4')[0]
b = ax.plot([], [], 'k-', label='Steer 5')[0]
c = ax.plot([], [], 'b-', label='Steer 6')[0]
d = ax.plot([], [], 'g-', label='Steer 7')[0]
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.set_ylim(0, 1500)
ax.set_xlim(0, 1500)
time_text = ax.text(0.02, 0.97, '', transform=ax.transAxes, fontsize=11,
    color='green')
line_ani = animation.FuncAnimation(fig, update_line, frames=500, fargs=(
    data, l, data2, k, data3, f, data4, a, data5, b, data6, c, data7, d))
plt.show()
line_ani.save('persp_500.mp4', writer=writer)

<mask token>
import matplotlib.pyplot as plt
from matplotlib import animation
import pandas as pd
import numpy as np
df = pd.read_csv('all_loc.csv')
df = df.drop(df.columns[0], 1)
Writer = animation.writers['ffmpeg']
writer = Writer(fps=14, metadata=dict(artist='Me'), bitrate=-1)


def update_line(num, data, line, data2, line2, data3, line3, data4, line4,
    data5, line5, data6, line6, data7, line7):
    line.set_data(data[..., :num])
    line2.set_data(data2[..., :num])
    line3.set_data(data3[..., :num])
    line4.set_data(data4[..., :num])
    line5.set_data(data5[..., :num])
    line6.set_data(data6[..., :num])
    line7.set_data(data7[..., :num])
    time_text.set_text('Frame: %.0f' % int(num))
    return line, line2, line3, line4, line5, line6, line7


data = np.array([df.iloc[:, 0].values, df.iloc[:, 1].values])
data2 = np.array([df.iloc[:, 2].values, df.iloc[:, 3].values])
data3 = np.array([df.iloc[:, 4].values, df.iloc[:, 5].values])
data4 = np.array([df.iloc[:, 6].values, df.iloc[:, 7].values])
data5 = np.array([df.iloc[:, 8].values, df.iloc[:, 9].values])
data6 = np.array([df.iloc[:, 10].values, df.iloc[:, 11].values])
data7 = np.array([df.iloc[:, 12].values, df.iloc[:, 13].values])
fig = plt.figure()
ax = fig.add_subplot(111)
l, = ax.plot([], [], 'r-', label='Steer 1')
k = ax.plot([], [], 'c-', label='Steer 2')[0]
f = ax.plot([], [], 'y-', label='Steer 3')[0]
a = ax.plot([], [], 'm-', label='Steer 4')[0]
b = ax.plot([], [], 'k-', label='Steer 5')[0]
c = ax.plot([], [], 'b-', label='Steer 6')[0]
d = ax.plot([], [], 'g-', label='Steer 7')[0]
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.set_ylim(0, 1500)
ax.set_xlim(0, 1500)
time_text = ax.text(0.02, 0.97, '', transform=ax.transAxes, fontsize=11,
    color='green')
line_ani = animation.FuncAnimation(fig, update_line, frames=500, fargs=(
    data, l, data2, k, data3, f, data4, a, data5, b, data6, c, data7, d))
plt.show()
line_ani.save('persp_500.mp4', writer=writer)

'''
@author: Abdullah Sourav
The structure of script is based on @Sina's matplotlib animation tutorials ( https://bit.ly/2rfaxP3 )

The script is written to plot the locations of 7 tracked objects. By changing the number of data series [data, data2, data3,....] 
and output line [line, line2, line3,....], it can be edited to track different number of objects.

'''

import matplotlib.pyplot as plt
from matplotlib import animation
import pandas as pd
import numpy as np

# read data from csv file and drop the first row as it does not contain any location but the frame number
df = pd.read_csv("all_loc.csv")
df = df.drop(df.columns[0], 1)

# writer function initiation
Writer = animation.writers['ffmpeg']
writer = Writer(fps=14, metadata =dict(artist = "Me"), bitrate = -1)

# takes 7 data series and draw 7 lines
def update_line(num, data, line, data2, line2, data3, line3, data4, line4, data5, line5, data6, line6, data7, line7):
    line.set_data(data[...,:num])
    line2.set_data(data2[...,:num])
    line3.set_data(data3[...,:num])
    line4.set_data(data4[...,:num])
    line5.set_data(data5[...,:num])
    line6.set_data(data6[...,:num])
    line7.set_data(data7[...,:num])
    time_text.set_text("Frame: %.0f" % int(num))
    return line, line2, line3, line4, line5, line6, line7

# x, y locations of each object is converted into numpy array
data = np.array([df.iloc[:,0].values,df.iloc[:,1].values])
data2 = np.array([df.iloc[:,2].values,df.iloc[:,3].values])
data3 = np.array([df.iloc[:,4].values,df.iloc[:,5].values])
data4 = np.array([df.iloc[:,6].values,df.iloc[:,7].values])
data5 = np.array([df.iloc[:,8].values,df.iloc[:,9].values])
data6 = np.array([df.iloc[:,10].values,df.iloc[:,11].values])
data7 = np.array([df.iloc[:,12].values,df.iloc[:,13].values])

# figure and line properties
fig = plt.figure()
ax = fig.add_subplot(111)
l, = ax.plot([], [], 'r-', label = "Steer 1")
k= ax.plot([], [], 'c-', label = "Steer 2")[0]
f= ax.plot([], [], 'y-', label = "Steer 3")[0]
a= ax.plot([], [], 'm-', label = "Steer 4")[0]
b= ax.plot([], [], 'k-', label = "Steer 5")[0]
c= ax.plot([], [], 'b-', label = "Steer 6")[0]
d= ax.plot([], [], 'g-', label = "Steer 7")[0]

# place legend outside the plot
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

# hide the axes marker and ticks 
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)

# set the limits based on your data
ax.set_ylim(0,1500)
ax.set_xlim(0,1500)


# create the video and save into the local directories, change the "frames=500" to any desirable number of frames you want to plot 
time_text = ax.text(0.02,0.97,"", transform = ax.transAxes, fontsize = 11, color="green")
line_ani = animation.FuncAnimation(fig, update_line, frames=500, fargs = (data, l, data2, k, data3, f, 
                                                                          data4, a, data5,b, data6,c, data7, d))
plt.show()
line_ani.save("persp_500.mp4", writer= writer)
