Value Error: x and y must have the same first dimension
<p>Let me quickly brief you first, I am working with a .txt file with 5400 data points. Each is a 16 second average over a 24 hour period (24 hrs * 3600 s/hr = 86400...86400/16 = 5400). In short this is the average magnetic strength in the z direction for an inbound particle field curtsy of the Advanced Composition Experiment satellite. Data publicly available <a href="http://www.srl.caltech.edu/ACE/ASC/level2/index.html" rel="nofollow">here</a>. So when I try to plot it says the error </p>

<pre><code>Value Error: x and y must have the same first dimension
</code></pre>

<p>So I created a numpy lin space of 5400 points broken apart by 16 units. I did this because I thought that my dimensions didn't match with my previous array that I had defined. But now I am sure these two array's are of the same dimension and yet it still gives back that Value Error. The code is as follows:</p>

<p><strong>First try (without the linspace):</strong></p>

<pre><code>import numpy as np
import matplotlib as plt

Bz = np.loadtxt(r"C:\Users\Schmidt\Desktop\Project\Data\ACE\MAG\ACE_MAG_Data_20151202_GSM.txt", dtype = bytes).astype(float)

Start_ACE = dt.date(2015,12,2)
Finish_ACE = dt.date(2015,12,2)

dt_Mag = 16

time_Mag = np.arange(Start_ACE, Finish_ACE, dt_Mag)

plt.subplot(3,1,1)
plt.plot(time_Mag, Bz)
plt.title('Bz 2015 12 02')
</code></pre>

<p><strong>Second Try (with linspace):</strong></p>

<pre><code>import numpy as np
import matplotlib as plt

Bz = np.loadtxt(r"C:\Users\Schmidt\Desktop\Project\Data\ACE\MAG\ACE_MAG_Data_20151202_GSM.txt", dtype = bytes).astype(float)

Mag_time = np.linspace(0,5399,16, dtype = float)

plt.subplot(3,1,1)
plt.plot(Mag_time, Bz)
plt.title('Bz 2015 12 02')
</code></pre>

<p>Other than it being a dimensional problem I don't know what else could be holding back this plotting procedure back.</p>

<p><strong>Full traceback:</strong></p>

<pre><code>ValueError                                Traceback (most recent call last)
&lt;ipython-input-68-c5dc0bdf5117&gt; in &lt;module&gt;()
      1 plt.subplot(3,1,1)
----&gt; 2 plt.plot(Mag_time, Bz)
      3 plt.title('Bz 2015 12 02')

C:\Users\Schmidt\Anaconda3\lib\site-packages\matplotlib\pyplot.py in plot(*args, **kwargs)
   3152         ax.hold(hold)
   3153     try:
-&gt; 3154         ret = ax.plot(*args, **kwargs)
   3155     finally:
   3156         ax.hold(washold)

C:\Users\Schmidt\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
   1809                     warnings.warn(msg % (label_namer, func.__name__),
   1810                                   RuntimeWarning, stacklevel=2)
-&gt; 1811             return func(ax, *args, **kwargs)
   1812         pre_doc = inner.__doc__
   1813         if pre_doc is None:

C:\Users\Schmidt\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, *args, **kwargs)
   1422             kwargs['color'] = c
   1423 
-&gt; 1424         for line in self._get_lines(*args, **kwargs):
   1425             self.add_line(line)
   1426             lines.append(line)

C:\Users\Schmidt\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _grab_next_args(self, *args, **kwargs)
    384                 return
    385             if len(remaining) &lt;= 3:
--&gt; 386                 for seg in self._plot_args(remaining, kwargs):
    387                     yield seg
    388                 return

C:\Users\Schmidt\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
    362             x, y = index_of(tup[-1])
    363 
--&gt; 364         x, y = self._xy_from_xy(x, y)
    365 
    366         if self.command == 'plot':

C:\Users\Schmidt\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _xy_from_xy(self, x, y)
    221         y = _check_1d(y)
    222         if x.shape[0] != y.shape[0]:
--&gt; 223             raise ValueError("x and y must have same first dimension")
    224         if x.ndim &gt; 2 or y.ndim &gt; 2:
    225             raise ValueError("x and y can be no greater than 2-D")

ValueError: x and y must have same first dimension
</code></pre>

<p>The problem was the selection of array creation. Instead of linspace, I should have used arange. </p>

<pre><code>Mag_time = np.arange(0,86400, 16, dtype = float)
</code></pre>

python numpy matplotlib