Python Forum

Full Version: Error When Plotting ValueError: x and y must have same first dimension
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all

I was hoping someone could help me.

I am trying to create a series of plots from a large data set.

But every plot has a different set of X & Y values.

In the attachment I want to plot Column 5 with Column 6 for rows between 0 and 20.

The next plot would start also plot Column 5 with Column 6 but rows between 21 and 41.

The code I have is as follows:-

axes[0].plot((range(int((df_raw_data.iloc[start_counter,5])),(int(df_raw_data.iloc[end_counter,5])))),(range((int(df_raw_data.iloc[start_counter,6])),(int(df_raw_data.iloc[end_counter,6])))))


I loop through the dataset making start_counter = 0 and end_counter = 20 and once i plot the data i set start_counter = 21 and end_counter = 41 (thats the idea anyway).

The problem is that i keep getting the following error:-

  File "C:\Analysis.py", line 81, in Ploting_data
    axes[0].plot((range(int((df_raw_data.iloc[start_counter,5])),(int(df_raw_data.iloc[end_counter,5])))),(range((int(df_raw_data.iloc[start_counter,6])),(int(df_raw_data.iloc[end_counter,6])))))

  File "C:\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1743, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]

  File "C:\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 273, in __call__
    yield from self._plot_args(this, kwargs)

  File "C:\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 399, in _plot_args
    raise ValueError(f"x and y must have same first dimension, but "

ValueError: x and y must have same first dimension, but have shapes (1761,) and (0,)
Can some help point me in the right direction?

Thank you.
Something like the following should work:

start_counter = 0
end_counter = 20
axes[0].plot(df_raw_data.iloc[start_counter:end_counter,5], df_raw_data.iloc[start_counter:end_counter,6])