I am having difficulties on plotting time on the xaxis. I have some overlapping labels. See below:

This is my code:
time=datenum(0,0,0,0,0,timeinseconds);
labs=1:10:length(time);
figure(3);
plotyy(time,xvalue,time,dens);
datetick('x','HH:MM');
set(gca,'XTick',time(labs),'XTickLabel',time(labs));
legend('xval','CDF');
title('Crash on Oct.10 2008 at 15:59pm');
xlabel('Time');
First, why are the labels overlapping with the old ones? And secondly, how I can get the label to rotate 90degrees? I tried some other matlab functions to turn the labels but none seem able to tackle time format labels.
Calling
plotyyyou create twoaxisobjects. Your overlap problem does probably come from the fact that you modify only one set of those axis, while leaving the other as it was originally set up.One option is handling both of the created axis when you call
plotyyby:Your first option here is setting up both of the axis, contained within the array of handlers
AX, via changing the'XTick'propriety as:But you also have the option of leaving the labels for the second axis empty, replacing the second line above:
The official documentation of plotyy and Using Multiple X- and Y-Axes can be of further help for you.
If you take a look on the example there, namely, plotyy documentation:
and as you did before, try to modify only the
AX(2), which is equivalent to what you got writinggca:you will observe that the same overlapping error takes place.
With respect to rotating the labels 90 deg, I’m afraid that’s not currently supported by Matlab. However, you can probably get that done using one of the available packages on FileExchange. Either xticklabelrotate or Rotate Tick Label could be the one.