How to make a plot show all 24hours, one by one, on the x-axis
15 views (last 30 days)
Show older comments
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')
title('Prodution')
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
Accepted Answer
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);
plot(xdate, Prodution)
and you should see the hours along the x-axis.
0 Comments
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!