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>I ended up finding a way to add the scatter plot to the same animation. The key was to use <code>scat.set_offsets</code> to set the data. The changes that are needed is as follows:</p>

<pre><code>def update_plot(num, x, y, line, scat):
    # ...
    scat.set_offsets([x[num - 1], y[num - 1]])
    return line, scat

def plot_circle():
    # ...
    scat = ax.scatter([0], [0], color = 'k') # Set the dot at some arbitrary position initially
    ani = animation.FuncAnimation(fig, update_plot, len(x), fargs=[x, y, line, scat], interval = 1, blit = False)
    plt.show()
</code></pre>

python matplotlib plot