Python Forum
ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, (/thread-32894.html)

Pages: 1 2


RE: ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, - buran - Mar-16-2021

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


RE: ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, - hobbyist - Mar-16-2021

My fault! I didn't see there is an excel file attached...!


RE: ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, - hobbyist - Mar-17-2021

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/12608788/changing-the-tick-frequency-on-x-or-y-axis-in-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?)


RE: ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, - buran - Mar-17-2021

(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/api/pandas.DataFrame.resample.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?


RE: ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, - buran - Mar-17-2021

And maybe I should have asked long ago - can you upload your file or at least sample of your data?


RE: ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, - hobbyist - Mar-21-2021

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?


RE: ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, - buran - Mar-21-2021

Sorry, I've done what I can to help you


RE: ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, - hobbyist - Mar-22-2021

@buran: I know that and I appreciate it! Thanks!