Plot Day of Year with Time

6 vues (au cours des 30 derniers jours)
Edgar
Edgar le 22 Nov 2022
Commenté : Star Strider le 5 Déc 2022
I'm trying to plot data with the headers 1-8 as my y-axis and the day of year with time in the x-axis, to show something similar as the "Example.png".
  2 commentaires
Dyuman Joshi
Dyuman Joshi le 23 Nov 2022
The values in the headers are varying for each time, it will only give you vertical lines (with the way you want to plot).
If you want a continuous graph as the picture you attached, you will need a continuous data.
Also there's a lot of data missing in the file attached.
Star Strider
Star Strider le 5 Déc 2022
See duplicate post: Plot Day of Year with Time (30 Nov 2022 at 14:48)

Connectez-vous pour commenter.

Réponses (1)

Seth Furman
Seth Furman le 5 Déc 2022
Importing the data
Normally, we could use readtimetable to import Data.csv, but The Time variable has an unusual format, so we have to do some extra work to import Data.csv as a timetable.
t = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1203593/Data.csv",TextType="string");
t.Properties.VariableNames = t{1,:};
t = t(2:end,:);
t = addvars(t,double(extractBefore(t.Time,4)),Before="1",NewVariableNames="DayOfYear");
t.Time = duration(extractAfter(t.Time,4));
tt = table2timetable(t)
tt = 366×9 timetable
Time DayOfYear 1 2 3 4 5 6 7 8 ________ _________ ______ ______ ______ ______ ______ ______ ______ ______ 22:59:19 242 NaN NaN NaN NaN NaN NaN NaN NaN 22:59:23 242 NaN NaN NaN NaN NaN NaN NaN NaN 22:59:58 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:00:08 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:00:32 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:00:35 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:00:57 242 4.0894 4.0915 4.0956 4.0935 4.0915 4.0956 4.0935 4.0925 23:01:21 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:01:43 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:01:46 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:02:22 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:02:33 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:02:56 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:03:00 242 NaN NaN NaN NaN NaN NaN NaN NaN 23:03:21 242 4.0894 4.0915 4.0946 4.0946 4.0925 4.0967 4.0915 4.0925 23:04:08 242 NaN NaN NaN NaN NaN NaN NaN NaN
Presumably, we have a particular year for which the data were measured. Assuming that year was 2022, we can add datetime(2022,1,1) to our day-of-year to get the date, which we can then add to the time of day.
Note: We must use caldays instead of days, because not every day in a year is exactly 24 hours.
tt2 = tt;
tt2.Time = tt2.Time + datetime(2022,1,1) + caldays(tt2.DayOfYear) % OR caldays(tt2.DayOfYear-1)
tt2 = 366×9 timetable
Time DayOfYear 1 2 3 4 5 6 7 8 ____________________ _________ ______ ______ ______ ______ ______ ______ ______ ______ 31-Aug-2022 22:59:19 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 22:59:23 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 22:59:58 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:00:08 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:00:32 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:00:35 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:00:57 242 4.0894 4.0915 4.0956 4.0935 4.0915 4.0956 4.0935 4.0925 31-Aug-2022 23:01:21 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:01:43 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:01:46 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:02:22 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:02:33 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:02:56 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:03:00 242 NaN NaN NaN NaN NaN NaN NaN NaN 31-Aug-2022 23:03:21 242 4.0894 4.0915 4.0946 4.0946 4.0925 4.0967 4.0915 4.0925 31-Aug-2022 23:04:08 242 NaN NaN NaN NaN NaN NaN NaN NaN
Remove rows with missing data.
tt2 = rmmissing(tt2)
tt2 = 48×9 timetable
Time DayOfYear 1 2 3 4 5 6 7 8 ____________________ _________ ______ ______ ______ ______ ______ ______ ______ ______ 31-Aug-2022 23:00:57 242 4.0894 4.0915 4.0956 4.0935 4.0915 4.0956 4.0935 4.0925 31-Aug-2022 23:03:21 242 4.0894 4.0915 4.0946 4.0946 4.0925 4.0967 4.0915 4.0925 31-Aug-2022 23:05:45 242 4.0894 4.0904 4.0956 4.0935 4.0925 4.0967 4.0946 4.0925 31-Aug-2022 23:08:09 242 4.0894 4.0904 4.0956 4.0935 4.0915 4.0946 4.0956 4.0925 31-Aug-2022 23:10:34 242 4.0894 4.0894 4.0946 4.0925 4.0935 4.0967 4.0946 4.0925 31-Aug-2022 23:12:58 242 4.0894 4.0925 4.0956 4.0925 4.0915 4.0967 4.0935 4.0925 31-Aug-2022 23:15:22 242 4.0873 4.0915 4.0946 4.0946 4.0925 4.0967 4.0915 4.0946 31-Aug-2022 23:17:46 242 4.0883 4.0915 4.0935 4.0946 4.0915 4.0977 4.0935 4.0946 31-Aug-2022 23:20:10 242 4.0894 4.0904 4.0956 4.0935 4.0925 4.0967 4.0946 4.0925 31-Aug-2022 23:22:35 242 4.0894 4.0904 4.0956 4.0935 4.0925 4.0967 4.0935 4.0925 31-Aug-2022 23:25:00 242 4.0873 4.0915 4.0946 4.0946 4.0925 4.0977 4.0935 4.0946 31-Aug-2022 23:27:24 242 4.0883 4.0915 4.0935 4.0946 4.0925 4.0956 4.0935 4.0946 31-Aug-2022 23:29:47 242 4.0894 4.0904 4.0956 4.0946 4.0925 4.0967 4.0935 4.0925 31-Aug-2022 23:32:12 242 4.0883 4.0915 4.0956 4.0935 4.0904 4.0956 4.0935 4.0925 31-Aug-2022 23:34:37 242 4.0894 4.0915 4.0967 4.0935 4.0925 4.0967 4.0925 4.0935 31-Aug-2022 23:37:00 242 4.0894 4.0925 4.0946 4.0925 4.0935 4.0967 4.0935 4.0925
Visualize the timetable
It's not immediately clear to me how you'd like to visualize the data, but stackedplot is a good starting place for visualizing timetables.
stackedplot(tt2)

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by