Plotting an array of vectors in Python (pyplot)
<p>I'm trying to plot a large array of vectors using pyplot. Right now I've got</p>

<pre><code>import matplotlib.pyplot as plt
import numpy as np
import operator

t = np.arange(0, np.pi, .01)


def pos1(t):
    x1 = .72 * np.cos(13*t)
    y1 = .72 * np.sin(13*t)
    return x1, y1


def pos2(t):
    x2 = np.cos(8*t)
    y2 = np.sin(8*t)
    return x2, y2


def vec(t):
    x1 = pos1(t)[0]
    x2 = pos2(t)[0]
    y1 = pos1(t)[1]
    y2 = pos2(t)[1]
    x = np.subtract(x1, x2)
    y = np.subtract(y1, y2)
    return x, y


X = pos2(t)[0]
Y = pos2(t)[1]
U = vec(t)[0]
V = vec(t)[1]

plot1 = plt.figure()
plt.quiver(X, Y, U, V, headlength=4)
plt.show(plot1)
</code></pre>

<p>Where <code>pos1(t)</code>, <code>pos2(t)</code> and <code>vec(t)</code> are functions that return a tuple of the form <code>([a,...,z],[a1,...,z1])</code>.</p>

<p>This plot gives me something close to what I want, but the vector lengths are all wrong. the two functions, <code>pos1(t),pos2(t)</code> return a tuple of the point on a particular curve, and the <code>vec(t)</code> function is their difference, leading to a vector from a point on the first curve to a point on the second. My plot has the correct direction, but not magnitude. </p>

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

<p><code>quiver</code> handles length of arrows. It seems <code>quiver</code> is not what you need.</p>

<p><strong>Using regular <code>plot</code>:</strong></p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt


t = np.arange(0, 2 * np.pi, 0.01)
x0 = np.sin(8 * t)
y0 = np.cos(8 * t)
x1 = 0.72 * np.sin(13 * t)
y1 = 0.72 * np.cos(13 * t)

data = np.column_stack((x0, x1, y0, y1)).reshape(-1, 2)

plt.plot(*data, color='black')
plt.gca().set_aspect('equal', adjustable='box')
plt.show()
</code></pre>

<p><strong>Result:</strong></p>

<p><a href="http://i.imgur.com/iFEpcU5.png" rel="nofollow"><img src="http://i.imgur.com/iFEpcU5.png" alt="Result"></a>
<strong>Original:</strong></p>

<p><a href="http://i.stack.imgur.com/vB5Pm.gif" rel="nofollow"><img src="http://i.stack.imgur.com/vB5Pm.gif" alt="Original"></a></p>

python arrays numpy