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
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 165 Feb-24-2021, 05:09 PM
Last Post: bowlofred
  Receiving ValueError("bad input shape {0}".format(shape)) error SuryaCitizen 2 986 Jun-01-2020, 06:45 AM
Last Post: pyzyx3qwerty
  getting error ValueError: time data '' does not match format '%H:%M' srisrinu 2 1,564 Apr-09-2020, 11:12 AM
Last Post: srisrinu
  Error in the code ->ValueError: could not convert string to float: ' ' eagleboom 1 1,378 Nov-29-2019, 06:19 AM
Last Post: ThomasL
  ValueError: Index contains duplicate entries, cannot reshapeā€¯ error when I try to use Smiling29 11 3,940 Oct-26-2019, 09:52 PM
Last Post: Smiling29
  Wrong dimension for my plot Jemeronimo 1 611 Apr-25-2019, 06:19 PM
Last Post: Larz60+
  Dictionary multi dimension support sripylearn 3 1,126 Aug-14-2018, 03:50 PM
Last Post: buran
  Error Type: <class 'OSError'> And Error Type: <class 'ValueError'> runnerpaul 1 2,058 Jul-18-2017, 03:08 PM
Last Post: Larz60+
  Fast method of searching a string in a multi-dimension array? draems 6 3,239 Feb-20-2017, 01:02 PM
Last Post: Ofnuts
  Python Error (Traceback & ValueError) Help! helpplease 4 3,245 Dec-19-2016, 06:07 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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