title: Plotting a list of (x, y) coordinates in matplotlib
body: <p>I have a list of pairs <code>(a, b)</code> that I would like to plot with <code>matplotlib</code> in python as actual x-y coordinates. Currently, it is making two plots, where the index of the list gives the x-coordinate, and the first plot's y values are the <code>a</code>s in the pairs and the second plot's y values are the <code>b</code>s in the pairs.</p>
  <p>To clarify, my data looks like this: <code>li = [(a,b), (c,d), ... , (t, u)]</code>
  I want to do a one-liner that just calls <code>plt.plot()</code> incorrect.
  If I didn't require a one-liner I could trivially do:</p>
  <pre><code>xs = [x[0] for x in li]
  ys = [x[1] for x in li]
  plt.plot(xs, ys)
  </code></pre>
  <p>How can I get matplotlib to plot these pairs as x-y coordinates?</p>
  <hr />
  <h2>Sample data</h2>
  <pre class="lang-py prettyprint-override"><code># sample data
  li = list(zip(range(1, 14), range(14, 27)))
  
  li → [(1, 14), (2, 15), (3, 16), (4, 17), (5, 18), (6, 19), (7, 20), (8, 21), (9, 22), (10, 23), (11, 24), (12, 25), (13, 26)]
  </code></pre>
  <h2>Incorrect Plot</h2>
  <pre class="lang-py prettyprint-override"><code>plt.plot(li)
  plt.title('Incorrect Plot:\nEach index of the tuple plotted as separate lines')
  </code></pre>
  <p><a href="https://i.stack.imgur.com/3QW9V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3QW9V.png" alt="enter image description here" /></a></p>
  <h2>Desired Plot</h2>
  <ul>
  <li>This produces the correct plot, but to many lines of code are used to unpack <code>li</code>. I need to unpack and plot with a single line of code, not multiple list-comprehensions.</li>
  </ul>
  <pre class="lang-py prettyprint-override"><code>xs = [x[0] for x in li]
  ys = [x[1] for x in li]
  plt.plot(xs, ys)
  plt.title('Correct Plot:\nBut uses to many lines to unpack li')
  </code></pre>
  <p><a href="https://i.stack.imgur.com/5vfTB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5vfTB.png" alt="enter image description here" /></a></p>