Plotting line with marker as head
<p>I have the following code that produces an animation of drawing a circle.</p>

<pre><code>from math import cos, sin
import matplotlib.pyplot as plt
import matplotlib.animation as animation

def update_plot(num, x, y, line):
    line.set_data(x[:num], y[:num])
    line.axes.axis([-1.5, 1.5, -1.5, 1.5])
    return line

def plot_circle():
    x = []
    y = []
    for i in range(100):
        x.append(cos(i/10.0))
        y.append(sin(i/10.0))

    fig, ax = plt.subplots()
    line, = ax.plot(x, y, color = "k")
    ani = animation.FuncAnimation(fig, update_plot, len(x), fargs=[x, y, line], interval = 1, blit = False)
    plt.show()

plot_circle()
</code></pre>

<p>The line is longer than a full lap, and so to be able to still see the drawing when the line overlaps, I would like a marker that shows what is being drawn. I tried to add a scatter plot  into the update call, like</p>

<pre><code>scat = plt.scatter(0, 0)
ani = animation.FuncAnimation(fig, update_plot, len(x), fargs=[x, y, line, scat], interval = 1, blit = False)
</code></pre>

<p>and try to update the position of the scatter-plot point using <code>x[num]</code> and <code>y[num]</code> in <code>update_plot</code> without success. How can I achieve this effect?</p>

<p>You need to return <code>scat</code> in <code>update_plot()</code>. </p>

<p>Here is another method, draw the line with <code>markevery</code> argument:</p>

<pre><code>line, = ax.plot(x, y, "-o", color="k", markevery=100000)
</code></pre>

<p>reverse the points order:</p>

<pre><code>line.set_data(x[:num][::-1], y[:num][::-1])
</code></pre>

<p>for example:</p>

<pre><code>import numpy as np
import pylab as pl

t = np.linspace(0, 2, 100)
x = np.cos(t)
y = np.sin(t)

pl.plot(x[::-1], y[::-1], "-o", markevery=10000)
</code></pre>

<p>outputs:</p>

<p><a href="http://i.stack.imgur.com/oPAh6.png" rel="nofollow"><img src="http://i.stack.imgur.com/oPAh6.png" alt="enter image description here"></a></p>

python matplotlib plot