Question: I'm new to Matplotlib. I have the position of a person every second, and I am trying to make a graph showing this. I have managed to show it, but now I would like it to display different colors according to their speed. So, I need the plt.plot() color to depend on the distance between each pair of points, instead of being always the same.
This is what I have right now:

```
x = [i[0] for i in walk]
y = [i[1] for i in walk]
plt.clf()
fig = plt.gcf()
plt.axis([0, 391, 0, 578])
im = plt.imread('field.png')
cancha = plt.imshow(im)
plt.plot(x,y)
plt.axis('off')
plt.savefig( IMG_DIR + 'match.png',bbox_inches='tight')
plt.clf()

```

I would like to add some variable that defines the color according to distance([x[i],y[i]],[x[j],y[j]])

Does anyone know how to do this?

Thanks!

Answer: 
`scatter` will do what you want ([doc](http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.scatter)).

```
 plt.scatter(x,y,c=distance(x,y))
 plt.plot(x,y,'-') # adds lines between points

```

However, this will not connect the markers. If you want a line that is a different color on each segment I think you will have to plot a large number of two point lines.

EDIT: added `plot` as suggested in comments by Vorticity
You can also try `quiver`. It makes a direction field (arrows) plot.

```
import pylab as plt

x=[12, 13, 14, 15, 16]
y=[14, 15, 16, 17, 18]
speed=[1,2,3,4,5]

# Determine the direction by the difference between consecutive points
v_x=[j-i for i, j in zip(x[:-1], x[1:])] 
v_x.append(v_x[-1]) # The last point 
v_y=[j-i for i, j in zip(y[:-1], y[1:])]
v_y.append(v_y[-1]) # The last point

plt.quiver(x,y,v_x,v_y,speed)
plt.colorbar()
plt.xlim(11,17)
plt.ylim(13,19)
plt.show()

```

![enter image description here](https://i.stack.imgur.com/8gZjP.png)

If you want, you can also make the arrow size dependent on the speed at that position.