Plotting a simple 2D vector
<p>New to Python and just trying to accomplish what I think must be the simplest of tasks: plotting a basic 2D vector. However my online search has gotten me nowhere so I turn to stackoverflow with my very first question.</p>

<p>I Just want to plot a single 2D vector, let's call it my_vector. my_vector goes from (0,0) to (3,11).</p>

<p>What I have done is this:</p>

<pre><code>from __future__ import print_function
import numpy as np
import pylab as pl
%pylab inline

x_cords = np.arange(4)
y_cords = np.linspace(0, 11, 4)
my_vector = vstack([x_cords, y_cords])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(my_vector)
plt.show()
</code></pre>

<p>Which gives the following image (and totally not what I am after):</p>

<p><a href="http://i.stack.imgur.com/39KLk.png" rel="nofollow">a very wrong plot</a></p>

<p>However I have found that </p>

<pre><code>ax.plot(x_cords, y_cords)
</code></pre>

<p>instead of</p>

<pre><code>ax.plot(my_vector)
</code></pre>

<p>gives me the plot I am looking for but then I don't have that single vector I am after.</p>

<p>So how does one correctly plot a basic 2D vector? Thank you and sorry if this has indeed been posted somewhere else...</p>

<p>You can also unpack your 2D vector</p>

<pre><code>pl.plot(*my_vector)
</code></pre>

<p>Which is effectively just doing</p>

<pre><code>pl.plot(x_cords, y_cords)
</code></pre>

python matplotlib vector