title: Plot arrays of different lengths
body: <p>I'm plotting the error vs. number of iterations for three different algorithms. They take a different number of iterations to compute, so the arrays are of different length. Yet I want to plot all three lines on the same plot. Currently, I get this error when I use the following code:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  plt.plot(ks, bgd_costs, 'b--', sgd_costs, 'g-.', mbgd_costs, 'r')
  plt.title("Blue-- = BGD, Green-. = SGD, Red=MBGD")
  plt.ylabel('Cost')
  plt.xlabel('Number of updates (k)')
  plt.show()
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>    plt.plot(ks, bgd_costs, 'b--', sgd_costs, 'g-.', mbgd_costs, 'r')
    File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/pyplot.py", line 2995, in plot
      ret = ax.plot(*args, **kwargs)
    File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/axes/_axes.py", line 1331, in plot
      for line in self._get_lines(*args, **kwargs):
    File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/axes/_base.py", line 312, in _grab_next_args
      for seg in self._plot_args(remaining[:isplit], kwargs):
    File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/axes/_base.py", line 281, in _plot_args
      x, y = self._xy_from_xy(x, y)
    File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/axes/_base.py", line 223, in _xy_from_xy
      raise ValueError("x and y must have same first dimension")
  ValueError: x and y must have same first dimension
  </code></pre>
  
  <p><strong>UPDATE</strong> </p>
  
  <p>Thanks to @ibizaman's answer, I made this plot:
  <img src="https://i.stack.imgur.com/jvMPg.png" alt="enter image description here"></p>