Weird display in date plotting
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everyone, I'm trying to plot a value in a graph, but there is a weird order is happened when I try it. There is a huge gap between last month of the year and first month of the next year, and then the whole year is compacting in a small area. Here's the results, code and the a part of the data I have.
figure
plot(br.Date,br.A)
hold on
plot(br.Date,br.B)
'2009-12' 5.45000000000000 55.7200000000000
'2010-01' 6.04000000000000 55.2500000000000
'2010-02' 6.72000000000000 54.5000000000000
'2010-03' 7.29000000000000 54.4400000000000
'2010-04' 8.06000000000000 53.2600000000000
'2010-05' 8.61000000000000 52.7700000000000
'2010-06' 9.24000000000000 52.8600000000000
'2010-07' 9.88000000000000 52.6800000000000
'2010-08' 10.7600000000000 51.3400000000000
'2010-09' 11.5400000000000 49.8700000000000
'2010-10' 12.3900000000000 49.2100000000000
'2010-11' 13.3500000000000 48.1600000000000
'2010-12' 14.8500000000000 46.9400000000000
'2011-01' 15.6800000000000 46
The weird result in some screenshots:
There's no other data in between.
And the whole year escalated in a small area for no reason.
2 Kommentare
Antworten (1)
Stephen23
am 12 Feb. 2024
Bearbeitet: Stephen23
am 12 Feb. 2024
Lets convert your data into DATETIME (as they should be) and PLOT them:
Date = {'2009-12';'2010-01';'2010-02';'2010-03';'2010-04';'2010-05';'2010-06';'2010-07';'2010-08';'2010-09';'2010-10';'2010-11';'2010-12';'2011-01'};
A = [5.45;6.04;6.72;7.29;8.06;8.61;9.24;9.88;10.76;11.54;12.39;13.35;14.85;15.68];
B = [55.72;55.25;54.5;54.44;53.26;52.77;52.86;52.68;51.34;49.87;49.21;48.16;46.94;46];
T = table(Date,A,B)
T = convertvars(T,'Date',@(c)datetime(c,'InputFormat','y-M','Format','y-MM')) % much better!
plot(T.Date,T.A, T.Date,T.B)
1 Kommentar
Stephen23
am 12 Feb. 2024
Bearbeitet: Stephen23
am 12 Feb. 2024
Using your uploaded datafile:
fnm = 'browser-ww-monthly-200901-202401.csv';
opt = detectImportOptions(fnm, 'Delimiter',',');
opt = setvartype(opt,'Date','datetime');
opt = setvaropts(opt,'Date','InputFormat','y-M', 'DatetimeFormat','y-MM');
tbl = readtimetable(fnm,opt)
plot(tbl,1:26)
legend('Location','bestoutside')
Or
plot(tbl.Date,tbl.Chrome, tbl.Date,tbl.IE, tbl.Date,tbl.Firefox)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!