Weird display in date plotting

3 views (last 30 days)
Ogut Su Karagün
Ogut Su Karagün on 12 Feb 2024
Edited: Stephen23 on 12 Feb 2024
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 Comments
Stephen23
Stephen23 on 12 Feb 2024
@Ogut Su Karagün: please upload your actual data in a MAT file by clicking the paperclip button.

Sign in to comment.

Answers (1)

Stephen23
Stephen23 on 12 Feb 2024
Edited: Stephen23 on 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 = 14×3 table
Date A B ___________ _____ _____ {'2009-12'} 5.45 55.72 {'2010-01'} 6.04 55.25 {'2010-02'} 6.72 54.5 {'2010-03'} 7.29 54.44 {'2010-04'} 8.06 53.26 {'2010-05'} 8.61 52.77 {'2010-06'} 9.24 52.86 {'2010-07'} 9.88 52.68 {'2010-08'} 10.76 51.34 {'2010-09'} 11.54 49.87 {'2010-10'} 12.39 49.21 {'2010-11'} 13.35 48.16 {'2010-12'} 14.85 46.94 {'2011-01'} 15.68 46
T = convertvars(T,'Date',@(c)datetime(c,'InputFormat','y-M','Format','y-MM')) % much better!
T = 14×3 table
Date A B _______ _____ _____ 2009-12 5.45 55.72 2010-01 6.04 55.25 2010-02 6.72 54.5 2010-03 7.29 54.44 2010-04 8.06 53.26 2010-05 8.61 52.77 2010-06 9.24 52.86 2010-07 9.88 52.68 2010-08 10.76 51.34 2010-09 11.54 49.87 2010-10 12.39 49.21 2010-11 13.35 48.16 2010-12 14.85 46.94 2011-01 15.68 46
plot(T.Date,T.A, T.Date,T.B)
  1 Comment
Stephen23
Stephen23 on 12 Feb 2024
Edited: Stephen23 on 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)
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
tbl = 181×26 timetable
Date Chrome IE Firefox Safari Opera EdgeLegacy Edge YandexBrowser x360SafeBrowser Maxthon SogouExplorer Chromium UCBrowser CocCoc QQBrowser Mozilla SonyPS3 Android AOL SeaMonkey PaleMoon RockMelt Phantom Iron TheWorld Other _______ ______ _____ _______ ______ _____ __________ ____ _____________ _______________ _______ _____________ ________ _________ ______ _________ _______ _______ _______ ____ _________ ________ ________ _______ ____ ________ _____ 2009-01 1.38 65.41 27.03 2.57 2.92 0 0 0 0 0 0 0 0 0 0 0.15 0.08 0 0.27 0.04 0 0 0 0 0 0.16 2009-02 1.52 64.43 27.85 2.59 2.95 0 0 0 0 0 0 0 0 0 0 0.15 0.07 0 0.26 0.04 0 0 0 0 0 0.15 2009-03 1.73 62.52 29.4 2.73 2.94 0 0 0 0 0 0 0 0 0 0 0.16 0.08 0 0.25 0.03 0 0 0 0 0 0.15 2009-04 2.07 61.88 29.67 2.75 2.96 0 0 0 0 0 0 0 0 0 0 0.17 0.1 0 0.24 0.03 0 0 0 0 0 0.14 2009-05 2.42 62.09 28.75 2.65 3.23 0 0 0 0 0 0 0 0 0 0 0.4 0.09 0 0.21 0.03 0 0 0 0 0 0.14 2009-06 2.82 59.49 30.33 2.93 3.36 0 0 0 0 0 0 0 0 0 0 0.55 0.11 0 0.21 0.03 0 0 0 0 0 0.17 2009-07 3.01 60.11 30.5 3.02 2.64 0 0 0 0 0 0 0 0 0 0 0.2 0.14 0 0.2 0.03 0 0 0 0 0 0.15 2009-08 3.38 58.69 31.28 3.25 2.67 0 0 0 0 0 0 0 0 0 0 0.24 0.15 0 0.19 0.03 0 0 0 0 0 0.11 2009-09 3.69 58.37 31.34 3.28 2.62 0 0 0 0 0 0 0 0 0 0 0.26 0.12 0 0.18 0.03 0 0 0 0 0 0.1 2009-10 4.17 57.96 31.82 3.47 1.88 0 0 0 0 0 0 0 0 0 0 0.28 0.13 0 0.17 0.03 0 0 0 0 0 0.09 2009-11 4.66 56.57 32.21 3.67 2.02 0 0 0 0 0 0 0 0 0 0 0.44 0.14 0 0.16 0.03 0 0 0 0 0 0.1 2009-12 5.45 55.72 31.97 3.48 2.06 0 0 0 0 0.28 0 0 0 0 0 0.6 0.15 0 0.14 0.03 0 0 0 0 0 0.11 2010-01 6.04 55.25 31.64 3.76 2 0 0 0 0 0.38 0 0 0 0 0 0.48 0.15 0 0.14 0.03 0 0 0 0 0 0.13 2010-02 6.72 54.5 31.82 4.08 1.97 0 0 0 0 0.3 0 0 0 0 0 0.16 0.13 0 0.14 0.03 0 0 0 0 0 0.14 2010-03 7.29 54.44 31.27 4.16 1.97 0 0 0 0 0.28 0 0 0 0 0 0.16 0.13 0 0.13 0.03 0 0 0 0 0 0.13 2010-04 8.06 53.26 31.74 4.23 1.82 0 0 0 0 0.26 0 0 0 0 0 0.16 0.14 0 0.12 0.03 0 0 0 0 0 0.17
plot(tbl,1:26)
legend('Location','bestoutside')
Or
plot(tbl.Date,tbl.Chrome, tbl.Date,tbl.IE, tbl.Date,tbl.Firefox)

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!