Adjust intervals of x-axis in the plot!

12 views (last 30 days)
BN
BN on 4 Feb 2020
Commented: BN on 4 Feb 2020
Hey all,
I have SI and Date which I want to plot them. The Date is in a monthly format from 1989 to 2018 (360 months). I haven't any idea why the x interval divided into 5 years by Matlab:
But I want to set it in the monthly format.
Also, any idea how to get rid of the green line? I don't want it and I don't know why it is showing today? Yesterday I haven't this problem (the green line didn't show yesterday)
Any advice highly appreciated.
%plot vector
plot(Date,SI, 'linewidth',1.5)
xlabel('time step')
%Modify "time step"
ylabel('Precipitation')
  4 Comments
Rik
Rik on 4 Feb 2020
Even after rotating the ticks they will not be readable.
What release are you using?
BN
BN on 4 Feb 2020
Dear Rik, I am using Matlab R2018b.
If you think the cant be readable can you do me a favor and tell me how to use yearly intervals? like 1989 - 1990- ... 2018?
Thank you

Sign in to comment.

Accepted Answer

Rik
Rik on 4 Feb 2020
You can directly set the tick locations with the xticks function. Since your variable is already a datetime (and not datenum), you don't need the datetick function.
S=load('Date.mat');
Date=S.Date;
S=load('SI.mat');
SI=S.SI;
%since the last 11 columns of SI are empty, let's remove them
SI=SI(:,1);
f=figure(1);clf(f)
plot(Date,SI, 'linewidth',1.5)
xlabel('time step')
ylabel('Standardized Precipitation Index')
xticks(Date(1:12:end))
ax=gca;
set(ax,'XTickLabelRotation',45)

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!