Rachel Jennifer
Rachel Jennifer

Reputation: 503

How can I use hypertools plot the dynamic graphic about mouse trajectory according to time?

I find a powerful tool in kaggle which is hypertools. I find that it can plot dynamic graph. Just a single line code.

hyp.plot(temps, normalize='across', animate=True, chemtrails=True)

enter image description here

Sorry, the format .gif is more than 2MB. So I turn it into picture.However, you can watch this gif in this. I think this is petty cool. However, I do not know how use this tools to plot for my data. My data is a list of tuple (x, y, t) like this:

array([[  353.,  2607.,   349.],
       [  367.,  2607.,   376.],
       [  388.,  2620.,   418.],
       [  416.,  2620.,   442.],
       [  500.,  2620.,   493.],
       [  584.,  2620.,   547.],
       [  675.,  2620.,   592.],
       [  724.,  2620.,   643.],
       [  780.,  2620.,   694.],
       [  822.,  2620.,   742.],
       [  850.,  2633.,   793.],
       [  885.,  2633.,   844.],
       [  934.,  2633.,   895.],
       [  983.,  2633.,   946.],
       [ 1060.,  2633.,  1006.],
       [ 1144.,  2633.,  1063.],
       [ 1235.,  2633.,  1093.],
       [ 1284.,  2633.,  1144.],
       [ 1312.,  2633.,  1210.],
       [ 1326.,  2633.,  1243.],
       [ 1333.,  2633.,  1354.],
       [ 1354.,  2633.,  1408.],
       [ 1375.,  2646.,  1450.],
       [ 1452.,  2659.,  1492.],
       [ 1473.,  2672.,  1543.],
       [ 1480.,  2672.,  1954.]])

How can I use this powerful tool to plot mouse trajectory?

Upvotes: 0

Views: 185

Answers (1)

Andrew Heusser
Andrew Heusser

Reputation: 68

Hypertools only support animations for datasets with dimensionality>=3. Your mouse data is 3D but one of the axes is time, so visualizing that dimension as an animation is probably not that useful. You could try using the animation functions in matplotlib. For example:

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

fig, ax = plt.subplots()

data = np.random.randn(200,2)
line, = ax.plot(data[0,0], data[0,1])


def animate(i):
    line.set_data(data[:i,:].T)  # update the data
    return line,


# Init only required for blitting to give a clean slate.
def init():
    line.set_data(data[0,0], data[0,1])
    return line,

ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), 
init_func=init, interval=25, blit=True)
plt.xlim(min(data[:,0]), max(data[:,0]))
plt.ylim(min(data[:,1]), max(data[:,1]))
plt.show()

Upvotes: 1

Related Questions