title: ValueError: x and y must have same first dimension, but have shapes
body: <p>I wonder how to best solve the following problem in my script: &quot;ValueError: x and y must have same first dimension, but have shapes (1531,) and (1532,)&quot;.</p>
  <p>What is the problem here? The problem is that the x and y axis of the plot don't share the exact same number of values (input) to plot. The result is the error message above.</p>
  <p>Let us look at the code first:</p>
  <pre><code># Initialize
  import numpy as np
  import matplotlib.pyplot as plt
  from scipy import signal
  from matplotlib.pyplot import cm
  
  # Numpy.loadtxt – Loads data from a textfile.
  # Scipy.signal.welch – Creation of the power-spectrum via welch method. f, Welch creates the ideal frequencies (f, Welch = Power Spectrum or Power Spectral Density)
  Subjects = [&quot;Subject1&quot; &quot;Subject2&quot;]
  
  for Subject in Subjects:
      Txt = np.loadtxt(&quot;/datadir.../{0}/filename...{0}.txt&quot;.format(Subject), comments=&quot;#&quot;, delimiter=None,
                           converters=None, skiprows=0, usecols=0, unpack=False, ndmin=0, encoding=None, max_rows=None, like=None)
  
      f, Welch = signal.welch(Txt, fs=1.0, window=&quot;hann&quot;, nperseg=None, noverlap=None, nfft=3062, detrend=&quot;constant&quot;, return_onesided=True, scaling=&quot;density&quot;, axis=-1, average=&quot;mean&quot;)
  
      BypassZero1 = f[f &gt; 0.00000000000001] # Avoids &quot;RuntimeWarning: divide by zero encountered in log&quot;
      BypassZero2 = Welch[Welch &gt; 0.00000000000001]
  
      Log_f = np.log(BypassZero1, out=BypassZero1, where=BypassZero1 &gt; 0)
      Log_Welch = np.log(BypassZero2, out=BypassZero2, where=BypassZero2 &gt; 0)
  
      plt.plot(Log_f, Log_Welch)
  </code></pre>
  <p>The code lines &quot;BypassZero1&quot; and &quot;BypassZero2&quot; tell Python to only use values above 0.00000000000001 for both &quot;f&quot; and &quot;Welch&quot;. Otherwise the problem &quot;RuntimeWarning: divide by zero encountered in log&quot; would occur in the following step where I apply the logarithm for both axes (Log_f and Log_Welch).</p>
  <p>This is where the problem occurs for the last plt.plot line of the code. It seems that a different number of numeric values are &quot;left over&quot; for &quot;f&quot; and &quot;Welch&quot; after the previous step of using the Welch method and applying the logarithm for both axes.</p>
  <p>I wonder if there is a possibility to deal with the 0.xxx values provided in the .txt file. Currently, only values above 0.00000000000001 for both f and Welch are used. This will lead to the different number of values for x and y, hence resulting in the impossibility of plotting the data.</p>
  <p>What could be a solution for this problem?</p>