Adjust intervals of x-axis in the plot!

15 Ansichten (letzte 30 Tage)
BN
BN am 4 Feb. 2020
Kommentiert: BN am 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 Kommentare
Rik
Rik am 4 Feb. 2020
Even after rotating the ticks they will not be readable.
What release are you using?
BN
BN am 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rik
Rik am 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)

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by