Xticks as Days for specific data points
7 ビュー (過去 30 日間)
古いコメントを表示
Dear all,
I am computing Value at Risk estimates for different time horizons and I would like to plot them against regular days. I know that you can specify the ticks of the x-axis somehow via datetime, but i don't seem to get the syntax correctly. You can see my code below.
I calculated different VaRs for 10, 30, 125 and 250 days and plot those data points against those 250 days, but I only manage to do that evenly spaced (e.g. same space between 10 and 30 and 30 and 125) which is obviously wrong.
set(gca,'XTick',datetime(1,1,250),'Xticklabel',[10 30 125 250])
Any help would be highly appreciated.
Leo
0 件のコメント
回答 (1 件)
Steven Lord
2021 年 2 月 5 日
Something along the lines of that code should work if you plotted your data with datetime X data.
daysSinceJanuary1st = randi([0 364], 1, 10)
x = datetime(2021, 1, 1) + days(daysSinceJanuary1st)
h = plot(x, 1:10);
xticks(datetime(2021, 1:12, 1))
xlim(datetime([2021, 2022], 1, 1))
If you want to customize the ticks or the tick labels further, you may need or want to work with the ruler for the X axis directly.
theAxes = ancestor(h, 'axes');
theRuler = theAxes.XAxis
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
