I have a daily observation of price for 32 years. The first column is date and the second column is price.
I want to plot all the data( every days in month) but since the data period is too long, I want to write the years in the x-axis like a picture I attached.Data is attached.

 Réponse acceptée

Star Strider
Star Strider le 9 Sep 2022
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1120695/sample.csv', 'VariableNamingRule','preserve')
T1 = 1749×2 table
Date Adj Close __________ _________ 01/02/1990 24.87 02/02/1990 24.32 05/02/1990 24.54 06/02/1990 24.69 07/02/1990 24.29 08/02/1990 23.77 09/02/1990 23.69 12/02/1990 24.38 13/02/1990 23.76 14/02/1990 22.05 15/02/1990 19.71 16/02/1990 20.78 20/02/1990 22.78 21/02/1990 23.89 22/02/1990 22.54 23/02/1990 23.69
figure
plot(T1.Date, T1.('Adj Close'))
xtickformat('MMM dd yyyy')
set(gca,'XTickLabelRotation',90)
.

4 commentaires

neda fathi
neda fathi le 10 Sep 2022
Many thanks,
I repeat the code with the whole data , but because the main data is too long, it only shows every 5 years in the x-axis (pi is attatched). I want to have all years in the x-axis. the data is attached as well.
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1121370/vvv.csv')
T1 = 8125×2 table
Date Open __________ _____ 03/01/1990 18.19 04/01/1990 19.22 05/01/1990 20.11 08/01/1990 20.26 09/01/1990 22.2 10/01/1990 22.44 11/01/1990 20.05 12/01/1990 24.64 15/01/1990 26.34 16/01/1990 24.18 17/01/1990 24.16 18/01/1990 24.34 19/01/1990 22.5 22/01/1990 26.7 23/01/1990 24.72 24/01/1990 25.39
xty = unique(year(T1.Date));
xt = datetime(['Jan 01 ' num2str(xty(1))], 'InputFormat','MMM dd yyyy') + calyears(0:numel(xty))';
xt(1) = T1.Date(1);
figure
plot(T1.Date, T1.('Open'))
set(gca,'XTick',xt)
xtickformat('MMM dd yyyy')
set(gca,'XTickLabelRotation',90)
The ‘Jan 01 1990’ will not plot because it does not exist, so I replaced it with the first date that does exist. I cannot over-ride this with the 'XTickLabel' property with datetime arrays.
.
neda fathi
neda fathi le 10 Sep 2022
This is perfect! Many many thanks!!!
Star Strider
Star Strider le 10 Sep 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Polar Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by