Home > Enterprise >  How to change the frequency of x ticks for time data?
How to change the frequency of x ticks for time data?

Time:07-20

How can I change the frequency of my x ticks to every hour using matplotlib.pyplot? I looked at similar posts, but could not figure out how to apply their solutions to my data since I only have times, not full dates. Here's an example of my data:

Time        SRH_1000m
14:03:00    318
14:08:00    321
14:13:00    261
14:17:00    312
14:22:00    285

CodePudding user response:

See: enter image description here

CodePudding user response:

From your question, I think you want to plot this in a line/scatter plot, but the x-axis should be in HH:MM:SS format? I took your data, edited it so that the time is across a few hours and built a simple line plot. Hope this will help in what you are trying to achieve.

You will need to make sure your time column is in datetime format and then use 'set_major_formatter()' to set it to the format you need. I have used %H:%M:%S, but you can change it whatever you think works....

EDIT - The earlier response had an error, so updated one here. Along with the other items mentioned above, you need to convert the type to enter image description here

  • Related