'Matlab date line exceeds end date for some data

For the same code, I get two different date line graph. In second plot, there is a line after end date. I can't figure out why. My code is below.

for k=1:K
    figure(k);
    hold on;
    set(h,'FaceColor',[.9,0.9,0.9]);
    set(h,'LineStyle','none')
    plot(Dates(1,2:T),ly(k,:),'Color',[0, 0.4470, 0.7410], 'LineWidth',2.2);
    plot(Dates(1,2:T),CIb(k,:),'.k','MarkerSize',3.7);
    plot(Dates(1,2:T),CIu(k,:),'.k','MarkerSize',3.7);
    plot(Dates(1,2:T),lUncMod(k,1).*ones(T-1,1),'--r','LineWidth',1.5);
    plot(Dates(1,2:T),lCondMod(k,1).*ones(T-1,1),'b','LineWidth',1.5);
    plot(Dates(1,2:T),zeros(T-1,1),'k','LineWidth',0.1);
    set(gca,'XTick',XT,'XTickLabel',XTL);
    if k==1;
        title('$\hat{\lambda}_{m,t}$','FontSize',18,'Interpreter','latex');
        hold off;
    elseif k==2;
        title('$\hat{\lambda}_{smb,t}$','FontSize',18,'Interpreter','latex');
        hold off;
    end;
end;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source