How to make a plot show all 24hours, one by one, on the x-axis

22 views (last 30 days)
Luís Quesado
Luís Quesado on 31 Jan 2018
Commented: Ali on 30 Jun 2022
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)
plot(Hours_24, Prodution)
xlabel('Hours') %Legenda x
ylabel('MW') %Legenda y
datetick('x', 'HH')
grid on
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.
  1 Comment
Ali on 30 Jun 2022
J'ai besoin d'afficher l'axe dex en fonction des heures mais entre deux heures il y a un bar par exemple entre 5h et 6h j'ai besoin d'afficher un bar comment faire ca

Sign in to comment.

Accepted Answer

Walter Roberson
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
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);
plot(xdate, Prodution)
and you should see the hours along the x-axis.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!