Python Forum
Error When Plotting ValueError: x and y must have same first dimension
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error When Plotting ValueError: x and y must have same first dimension
#1
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.

Attached Files

Thumbnail(s)
   
Reply
#2
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])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Plotting by Time, error mansoorahs 1 724 May-16-2023, 09:46 AM
Last Post: Larz60+
  Array dimension don't match asja2010 0 1,072 Feb-23-2023, 04:22 PM
Last Post: asja2010
  x and y must have same first dimension, but have shapes (1,) and (50,) asja2010 5 2,592 Jan-12-2023, 07:24 PM
Last Post: deanhystad
Exclamation Error when plotting a graph. Oshadha 3 3,637 Mar-14-2022, 06:47 PM
Last Post: deanhystad
  Strange error ValueError: dimension mismatch Anldra12 0 1,960 Aug-17-2021, 07:54 AM
Last Post: Anldra12
  ValueError: dimension mismatch Anldra12 0 3,381 Jul-17-2021, 04:46 PM
Last Post: Anldra12
  ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, hobbyist 17 150,303 Mar-22-2021, 10:27 AM
Last Post: hobbyist
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 3,757 Feb-24-2021, 05:09 PM
Last Post: bowlofred
  Receiving ValueError("bad input shape {0}".format(shape)) error SuryaCitizen 2 3,503 Jun-01-2020, 06:45 AM
Last Post: pyzyx3qwerty
  getting error ValueError: time data '' does not match format '%H:%M' srisrinu 2 5,579 Apr-09-2020, 11:12 AM
Last Post: srisrinu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020