Xticks as Days for specific data points
    7 views (last 30 days)
  
       Show older comments
    
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 Comments
Answers (1)
  Steven Lord
    
      
 on 5 Feb 2021
        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
See Also
Categories
				Find more on Line Plots in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

