How do I set X axis date tick (properly...) ?

9 ビュー (過去 30 日間)
Pierre Lonfat
Pierre Lonfat 2018 年 4 月 30 日
回答済み: Pierre Lonfat 2018 年 5 月 26 日
Dear all,
I successfully managed to have my much desired x axis date tick with the following code:
title('Annex 1: S&P 500 and performance indicators','FontSize',24);
ylabel('Indice evolution - Zscore','FontSize',16);
xlabel('Date','FontSize',16)
d=graph.date(1,1):graph.date(end,1);
a=datevec(d);
[ii,jj]=unique(a(:,1));
set(gca,'xtick',d(jj),'xlim',[graph.date(1,1) graph.date(end,1)]);
%datetick('x','mmm-yy', 'keepticks');
leg=legend('S&P 500','Volume','Price earning','Volatility 90 days','location','northwest');
set(leg,'FontSize',14);
grid on;
And it give me the following result:
Now I want to convert that into date by using datetick: (just removing the comment % in front of datetick) and here is a very strange result...
Why Jan-18 is not respecting its previous position and not ending the time series (which is wrong, the end is March 2018). The corresponding 4.31 (numerical value) was in the correct position in the previous screenshot...
Thank you so much for helping me with that !
Pierre

採用された回答

Pierre Lonfat
Pierre Lonfat 2018 年 5 月 26 日
For all, datetick('x','mmm-yy', 'keepticks', 'keeplimits');
Voila ! You can actually set both.

その他の回答 (1 件)

Rajesh Balagam
Rajesh Balagam 2018 年 5 月 3 日
It seems in the new figure x-axis's max limit is changed to 'Jan-18'.
You can use the 'keeplimits' input argument to the datetick function to keep the original axis limits.
datetick('x','mmm-yy', 'keeplimits');
Or you can try manually setting the x-axis's limits using the xlim function.
  1 件のコメント
Pierre Lonfat
Pierre Lonfat 2018 年 5 月 26 日
編集済み: Pierre Lonfat 2018 年 5 月 26 日
Unfortunately it doesn't work :/...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAxes Appearance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by