Clear Filters
Clear Filters

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 views (last 30 days)
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.

Accepted Answer

dpb
dpb on 6 Jun 2015
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.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!