Interactive/Animated scatter plotting with matplotlib
<p>I want to animate the scatter plot based on the actual timestamp from the csv file (see below). I'm not so good with matplotlib and I know of the animation function and the ion()-function but I'm not sure how to implement it.
I read <a href="http://stackoverflow.com/questions/32268532/animate-a-scatterplot-with-pyplot">this</a> but it seemed very difficult to implement it in my way.
I have tried the code below but it only shows me every loop a new window with the actual data but I would like to have the animation in one window thanks in advance :):</p>

<pre><code>import pandas as pd
import matplotlib.pyplot as plt

start_time = 86930.00
end_time = 86934.00
df = pd.read_csv('Data.csv', delimiter=',')

for timestamp in range(int(start_time), int(end_time), 1):
    act_data = df.loc[df['timestamp'] == float(timestamp)]
    X = act_data.x
    Y = act_data.y
    plt.scatter(X, Y)
    plt.show()
</code></pre>

<p>Data.csv:</p>

<pre><code>timestamp,id,x,y
86930.00,1,1155.53,7155.05
86930.00,2,3495.08,8473.46
86931.00,1,3351.04,6402.27
86931.00,3,3510.59,8021.62
86931.00,2,2231.04,6221.27
86931.00,4,3710.59,8111.62
86932.00,2,3333.01,6221.27
86932.00,1,3532.59,3178.62
86933.00,3,1443.01,2323.27
86933.00,4,5332.59,1178.62
</code></pre>

<p>It would be cool if I could color the blobs by ID but not necessary :).</p>

<p>The quickest way to animate on the same axis is to use interactive plots, <code>plt.ion</code></p>

<pre><code>import pandas as pd
import matplotlib.pyplot as plt

start_time = 86930.00
end_time = 86934.00
df = pd.read_csv('Data.csv', delimiter=',')


fig, ax = plt.subplots(1,1)
plt.ion()
plt.show()

for timestamp in range(int(start_time), int(end_time), 1):
    act_data = df.loc[df['timestamp'] == float(timestamp)]
    X = act_data.x
    Y = act_data.y
    ax.scatter(X, Y)
    plt.pause(1.0)
</code></pre>

<p>Although, I suspect from your title you want something interactive, which you can also use a <code>matplotlib</code> <a href="http://matplotlib.org/examples/widgets/slider_demo.html" rel="nofollow">slider widget</a>. 
With you data,</p>

<pre><code>import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider

start_time = 86930.00
end_time = 86934.00
df = pd.read_csv('Data.csv', delimiter=',')


fig, ax = plt.subplots(1,1)
plt.subplots_adjust(bottom=0.25)
sax = plt.axes([0.25, 0.1, 0.65, 0.03])
slide = Slider(sax, 'time', start_time, end_time, valinit=start_time)

#Initial plot
act_data = df.loc[df['timestamp'] == float(int(start_time))]
s, = ax.plot(act_data.x, act_data.y, 'o')

def update(timestamp):
    act_data = df.loc[df['timestamp'] == float(int(timestamp))]
    X = act_data.x
    Y = act_data.y

    #Update data based on slider
    s.set_xdata(X)
    s.set_ydata(Y)

    #Reset axis limits
    ax.set_xlim([X.min()*0.9,X.max()*1.1])
    ax.set_ylim([Y.min()*0.9,Y.max()*1.1])

    fig.canvas.draw()

slide.on_changed(update)
plt.show()
</code></pre>

python pandas matplotlib