Monday, May 21, 2012

Vertical xtick Labels in Matlab graphs

This was taken from the mailing list entry available at: https://mailman.cae.wisc.edu/pipermail/help-octave/2009-July/036066.html
--------------------------------

here is a script that illustrates how to rotate the xtick label and put them vertically.

clear
## init demo plot
clf
plot(1:4);
xtick=[1 2 3 4];
set(gca,'xtick',xtick);
xticklabel=["a";"b";"c";"d"];
set(gca,'xticklabel',xticklabel);

## get position of current xtick labels
h = get(gca,'xlabel');
xlabelstring = get(h,'string');
xlabelposition = get(h,'position');

## construct position of new xtick labels
yposition = xlabelposition(2);
yposition = repmat(yposition,length(xtick),1);

## disable current xtick labels
set(gca,'xtick',[]);

## set up new xtick labels and rotate
hnew = text(xtick, yposition, xticklabel);
set(hnew,'rotation',90,'horizontalalignment','right');

No comments:

Post a Comment