Xticks as Days for specific data points
6 次查看(过去 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!
