Effacer les filtres
Effacer les filtres

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 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

dpb
dpb le 6 Juin 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.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by