MATLAB: Change the orientation of the xtick labels


How to change the orientation of the xtick labels while drawing a figure?

Best Answer

There's no way to directly change the orientation of the xtick labels (using plain old MATLAB). You can try a work-around:
1. Just use a smaller font for the whole figure (I know, not ideal if you have long strings at your tick locations, and it affects not just your xticks)
2. Replace xtick labels with your own, oriented string:
figure, plot(rand(20,1),'.')
oldticksX = get(gca,'xtick');
oldticklabels = cellstr(get(gca,'xtickLabel'));
tmp = text(oldticksX, zeros(size(oldticksX)), oldticklabels, 'rotation',-90,'horizontalalignment','left')
You can play with the Y-locations of these text labels to add a little bit of padding away from the x-axis. The downside of this approach is that the xticklabels will no longer update when you resize the figure (but the tick locations themselves will).
Hope this helped Dongping.