-1

I have timestamps for every minute in a day, and am graphing the corresponding radiation data. The time is a datatime object in the following form: *forgot to mention, these are each strings

>>>timestr0
2016-05-16 00:00:00
2016-05-16 00:01:00
2016-05-16 00:02:00
2016-05-16 00:03:00
2016-05-16 00:04:00
2016-05-16 00:05:00
2016-05-16 00:06:00
2016-05-16 00:07:00
2016-05-16 00:08:00
...

this is some code that I'm working with:

import matplotlib.pyplot as plt
fig, ax = plt.subplots(1,1)
        ax.plot(timestr0, dayds)

Because the time stamps are every minute, the xticks are entirely illegible. How can I format the xticks so that its every 30 minutes or so throughout the entire day? Also, is there a way to change the format so that instead of the entire date, it is just the hour and minutes (i.e. HH:mm)?

Thanks!

  • See [this](https://matplotlib.org/stable/api/dates_api.html#matplotlib.dates.MinuteLocator). – r-beginners Jul 06 '21 at 15:11
  • What are those? Timestamps? Strings? – Mad Physicist Jul 06 '21 at 15:13
  • @MadPhysicist sorry, they are strings – Shane Markus Jul 06 '21 at 15:16
  • 1
    Convert your strings to datetime and then you can use usual ticking mecahnisms. Your times are ISO strings, so I'd use `np.datetime64` – Jody Klymak Jul 06 '21 at 15:49
  • As a beginner, the most valuable two things to remember are that 1) your problem is unlikely to be unique, and that 2) if it's not working as expected, it's almost certainly your fault and not of the compiler/library/framework. In this case, #1 applies most: always research before asking. – Mad Physicist Jul 06 '21 at 16:00

1 Answers1

0

You can explicitly set the xticks for every 30th time point as follows (assuming your timestr0 is some array-like variable of datetimes):

ax.set_xticks(timestr0[::30])
Philip Ciunkiewicz
  • 2,652
  • 3
  • 12
  • 24