Adjust intervals of x-axis in the plot!

조회 수: 15 (최근 30일)
BN
BN 2020년 2월 4일
댓글: BN 2020년 2월 4일
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
Rik
Rik 2020년 2월 4일
Even after rotating the ticks they will not be readable.
What release are you using?
BN
BN 2020년 2월 4일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2020년 2월 4일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by