x-axis on plot has cushion to left and right (i.e. plot doesn't start at beginning, and ends early with remaining space in the chart
2 次查看(过去 30 天)
显示 更早的评论
Here is my code:
startDate=datenum(num2str(tday(1)),'yyyymmdd');
endDate=datenum(num2str(tday(end)),'yyyymmdd');
cumret=cumprod(1+combinedRet)-1;
x=linspace(startDate,endDate,length(cumret));
plot(x,cumret);
ax=gca;
datetick('x',2,'keepticks');
ax.XTickLabelRotation=45;
My start date and end date are 8/24/12 - 5/29/15. So why does the x-axis start at 5/11/12 and end at 8/24/15?
Also, how can I increase the number of dates shown on the x-axis?
Many thanks, I am very grateful.
0 个评论
采纳的回答
dpb
2015-6-6
datetick unless told differently via keeplimits uses an internal rounding alogrithm to pick the axes limits to make what it considers "nice" intervals and number of ticks.
If you want something specific for start and end then use
xlim([datenum(firstDate) datenum(lastDate)])
to set those limits specifically before calling datetick
You can set the tick marks as desired with
set(gca,'xtick',_datenumSequence_)
where datenumSequence is a series of datenums at the spacing you wish beginning and ending with the above axes limits.
更多回答(0 个)
另请参阅
类别
在 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!