# How to fix the ticklabels - time series analysis?

조회 수: 2(최근 30일)
댓글: dpb 5 May 2019
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,

### 채택된 답변

dpb 27 Apr 2019
편집: dpb 27 Apr 2019
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

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 5 May 2019
Oh...that was a cut 'n paste error...the divisor should have been/was intended to be the constant NumberAssets instead...