How to fix the ticklabels - time series analysis?

조회 수: 3 (최근 30일)
Nadezhda Dimitrova
Nadezhda Dimitrova 2019년 4월 27일
댓글: dpb 2019년 5월 5일
Hello,
I have a question with regard to the xlables when plotting timeseries.
It is a timeseries analysis with about 5000 observations (t) and 20 constituencies (N).
I would like to have on the x-axis the labels of t/N instead of the number of the data point. Therefore, I calculated C = t/N and tried to use it as a xticklabels but it does not really work:
--> which is clearly not (1:5000)/20
Here is the code:
%% Calculating the concentration ratio C = t/N
for i = 1 : size(Data200018,1) % size = 4579
concentrationRatio(:,i) = i./NumberAssets; % NumberAssets = 20
end
%%Plot
figure;
plot(AE,'b-')
hold on
plot(AEDK,'r-')
ylabel('Average error','FontSize',12)
xlabel('Concentration Ratio','FontSize',12)
xticklabels(concentrationRatio)
hold off
I know that it is probably simpler than I think but I can’t figure it out :) Many thanks in advance for any advices!
Best,
Nadya

채택된 답변

dpb
dpb 2019년 4월 27일
편집: dpb 2019년 4월 27일
Clearly, the ticklabels you wrote are (1:5000)/20. The first label is 0.05 --> 1/20, the second 0.10 --> 2/20, etc., etc., ...
Matlab did precisely what you asked it to... :)
The problem is the tick marks aren't every x value else't there would be 5,090 of them...you must label only the ticks; per the documentation tick labels are just a 1:1 mapping of the input ticklabel values to the tick locations; if there are more labels than ticks the rest are ignored; fewer and the array is used from the beginning as many times as needed. Since your axis has 10 intervals there are 11 ticks and you labeled them with the values [1:11]/20
Use
xticklabels(xticks/concentrationRatio)
instead to label the actual ticks at 1/20th tick value
  댓글 수: 2
Nadezhda Dimitrova
Nadezhda Dimitrova 2019년 5월 5일
Thanks a lot for the great explanation, @dpb!
It worked but in different lines as the dimensions of xticks and concentrationRatio were different. Very helpful, thanks!
dpb
dpb 2019년 5월 5일
Oh...that was a cut 'n paste error...the divisor should have been/was intended to be the constant NumberAssets instead...

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by