Rotating Axis Labels in MatlabFor a figure I need to prepare for a paper I needed to rotate the x-axis labels which were generated by "datetick" function in Matlab. I found some scripts at the Matlab Central, but none of them really did what I wanted without tweaking. I decided to write down how I modified the code -Rotate Tick Label- by Andrew Bliss .
Andrew's code actually almost worked. The only problem was that the labels were not showing up where they needed to be, they were slightly above the x axis. So here is what I used to modify my datetick generated x-axis. The code below is almost the same as Andrew's code with the difference of the 0.7 multiplier and additional font options.%rotate text %get current tick labels a=get(gca,'XTickLabel'); %erase current tick labels from figure set(gca,'XTickLabel',[]); %get tick label positions b=get(gca,'XTick'); c=get(gca,'YTick'); rot=45; %make new tick labels if rot<180 text(b,repmat(c(1)-.7*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','right','rotation',rot,'FontSize', 14, 'FontWeight', 'normal'); else text(b,repmat(c(1)-.7*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','left','rotation',rot, 'FontSize', 14, 'FontWeight', 'normal'); end As you can see I couldn't find a way to keep the axis labels and just rotate them. The above code, copies the label's and create a new text-box rotated by the requested amount. See Also:Mathworks File Exchange: Rotate Tick Label by Andrew Bliss |