How to make a plot show all 24hours, one by one, on the x-axis
22 views (last 30 days)
Hi. I'm trying to make a plot that should show energy production in every hour of the day. I tried this:
Hours_24 = (0:1:23)
xlabel('Hours') %Legenda x
ylabel('MW') %Legenda y
But the result is that the x-axis only shows 00:00 in every single hour. I don't know what i'm doing wrong.
Walter Roberson on 31 Jan 2018
Hours_24 = (0:1:23)/24;
datetick expects the values to be in serial datenum format, which is in full days, so to get hours shown you need to use hours as fraction of 1 day.
More Answers (1)
Geoff Hayes on 31 Jan 2018
Luis - try using datenum to generate an array of serial date numbers which you can then plot along the x-axis. The datetick assumes that this is the format of the data in the x-axis. Just change your code to
xdate = datenum(0,0,0,0:1:23,0,0);
and you should see the hours along the x-axis.