Posts: 8,169
Threads: 160
Joined: Sep 2016
Mar-16-2021, 02:40 PM
(This post was last modified: Mar-16-2021, 02:40 PM by buran.)
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
Posts: 144
Threads: 41
Joined: Jun 2020
My fault! I didn't see there is an excel file attached...!
Posts: 144
Threads: 41
Joined: Jun 2020
Mar-17-2021, 08:35 PM
(This post was last modified: Mar-17-2021, 08:36 PM by hobbyist.)
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:
1 |
days = mdates.HourLocator(byhour = ( 0 , 1200 ))
|
. . .
1 2 3 4 |
ax.grid
start,end = ax.get_xlim()
ax.xaxis.set_ticks(np.arrange(start,end, 100 ))
plt.show()
|
(How do I upload images?)
Posts: 8,169
Threads: 160
Joined: Sep 2016
Mar-17-2021, 09:00 PM
(This post was last modified: Mar-17-2021, 09:00 PM by buran.)
(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?
Posts: 8,169
Threads: 160
Joined: Sep 2016
And maybe I should have asked long ago - can you upload your file or at least sample of your data?
Posts: 144
Threads: 41
Joined: Jun 2020
Ok, I tried to use the rationale of your second example code that you have posted on post #9. And I use this command:
1 |
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?
Posts: 8,169
Threads: 160
Joined: Sep 2016
Sorry, I've done what I can to help you
Posts: 144
Threads: 41
Joined: Jun 2020
@buran: I know that and I appreciate it! Thanks!
|