title: Subtracting two plots in matplotlib
body: <p>I have two plots which I would like to subtract, but I encounter some errors. My code looks like this:</p>
  
  <p>In general:</p>
  
  <pre><code>for dataset in [Bxfft]:
      dataset = np.asarray(dataset)
      freqs, psd = signal.welch(dataset, fs=52718/300, window='hamming', nperseg=16384, scaling='spectrum')
      plt.semilogy(freqs[5:4600], psd[5:4600]/dataset.size**0, color='r', label='Bx')
  
      x = freqs[5:361]
      y = psd[5:361]
      x2 = freqs[5:4600]
      y2 = psd[5:4600]
  </code></pre>
  
  <p>What I try to accomplish is to subtract <code>x2 - x</code> and <code>y2 - y</code>. I tried to do this two ways, but I got some errors:</p>
  
  <ol>
  <li><p><code>o = x-x2[:,:361]
  o2 = y-y2[:,:361]
  plt.semilogy(o, o2 / dataset.size ** 0, color='r', label='Bx')</code></p></li>
  </ol>
  
  <p>And the error looks like this:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File
    "S:/Doktorat/Python/Data/Dekomp/substraction.py", line 57, in 
        o = x-x2[:,:4800] IndexError: too many indices for array</p>
  </blockquote>
  
  <ol start="2">
  <li><p><code>o = x2-x
  o2 = y2-y
  plt.semilogy(o, o2 / dataset.size ** 0, color='r', label='Bx')</code></p></li>
  </ol>
  
  <p>And the error looks like this:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File
    "S:/Doktorat/Python/Data/Dekomp/substraction.py", line 57, in 
        o = x2-x ValueError: operands could not be broadcast together with shapes (4595,) (356,)</p>
  </blockquote>
  
  <p>Any ideas what to do?</p>