Python Forum
ValueError: x and y must have same first dimension, but have shapes (11,) and (15406,
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: x and y must have same first dimension, but have shapes (11,) and (15406,
#11
You need to learn how to debug small programs and solve problems on your own. Did you open my sample excel file? did you see what is on row 1 (cells A1:B1)? Did you try to print the df? Did you try to adapt the code to your needs?

Because you don't bother to provide enough information (like sample xlsx file) I created my own with headers x and y. So 'x' and 'y' are columnn names in the dataframe.
you can access a column by name e.g. df.x or df['x']. The former is not possible if name has space in it. In this case only df['some name'] works
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#12
My fault! I didn't see there is an excel file attached...!
Reply
#13
Thanks a lot for your help, I really appreciate it!!
Ok, so here is what I get by using your code + xticks from this: https://stackoverflow.com/questions/1260...matplotlib link you have posted in a previous post. Ok, I can adjust the xticks, but they don't seem to be suitable/corresponding/relevant with the y-values. I believe the code prints all the ~15000 y-values. How can I get a sample of them, let's say 1500 y-values so that it is more readable?

My changes/adds to your 1st (of the 2) code are the following:

days = mdates.HourLocator(byhour=(0,1200))
. . .

ax.grid
start,end = ax.get_xlim()
ax.xaxis.set_ticks(np.arrange(start,end,100))
plt.show()
(How do I upload images?)
Reply
#14
(Mar-17-2021, 08:35 PM)hobbyist Wrote: How can I get a sample of them, let's say 1500 y-values so that it is more readable?
I don't even know what your data are, what they represent, what is the frequency, etc. This is really a question that is really not python, but depends on the specific domain. i.e. you can resample (look at https://pandas.pydata.org/docs/reference...ample.html) or aggregate in some way
e.g. if it is stock price data at minute tick. you can make them hourly or daily.
You can always take every 10th value

And by the way - look again at both my examples
In my example it is either using mdates.HourLocator(byhour=(0,1200)) and ax.xaxis.set_major_locator() or using ax.xaxis.set_ticks(). Or maybe you made respective change in respective snippet?
hobbyist likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#15
And maybe I should have asked long ago - can you upload your file or at least sample of your data?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#16
Ok, I tried to use the rationale of your second example code that you have posted on post #9. And I use this command:

time = mdates.drange(dt.datetime(2020, 6, 24, 0, 0, 0), dt.datetime(2020, 10, 9, 0, 0 ,0), dt.timedata(hours = 120))
2020,6,24 is the 1st timestamp + value of the excel file
2020,10,9 is the ~15000nd timestamp + value of the excel file

However instead of putting xticks throughout whole the x-axis of the plot, it puts them, only to a part. How can this happen?? Any idea?
Reply
#17
Sorry, I've done what I can to help you
hobbyist likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#18
@buran: I know that and I appreciate it! Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I design shapes on a curve in python? mervea 2 765 Sep-14-2023, 01:04 PM
Last Post: Pedroski55
  Array dimension don't match asja2010 0 1,019 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,483 Jan-12-2023, 07:24 PM
Last Post: deanhystad
  Shapes in Video finndude 0 632 Oct-07-2022, 03:30 PM
Last Post: finndude
  Shapes over video in tkinter finndude 1 927 Oct-04-2022, 06:14 PM
Last Post: deanhystad
  operands could not be broadcast together with shapes (337,451) (225,301) kevinabbot 0 1,537 Dec-14-2021, 04:02 PM
Last Post: kevinabbot
  Strange error ValueError: dimension mismatch Anldra12 0 1,937 Aug-17-2021, 07:54 AM
Last Post: Anldra12
  ValueError: dimension mismatch Anldra12 0 3,347 Jul-17-2021, 04:46 PM
Last Post: Anldra12
  Error When Plotting ValueError: x and y must have same first dimension JoeDainton123 1 9,017 Oct-04-2020, 12:58 PM
Last Post: scidam
  Wrong dimension for my plot Jemeronimo 1 1,988 Apr-25-2019, 06:19 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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