annotate _misc/figures/.svn/text-base/rotateticklabel.m.svn-base @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function th=rotateticklabel(h,rot,demo)
matthiasm@8 2 %ROTATETICKLABEL rotates tick labels
matthiasm@8 3 % TH=ROTATETICKLABEL(H,ROT) is the calling form where H is a handle to
matthiasm@8 4 % the axis that contains the XTickLabels that are to be rotated. ROT is
matthiasm@8 5 % an optional parameter that specifies the angle of rotation. The default
matthiasm@8 6 % angle is 90. TH is a handle to the text objects created. For long
matthiasm@8 7 % strings such as those produced by datetick, you may have to adjust the
matthiasm@8 8 % position of the axes so the labels don't get cut off.
matthiasm@8 9 %
matthiasm@8 10 % Of course, GCA can be substituted for H if desired.
matthiasm@8 11 %
matthiasm@8 12 % TH=ROTATETICKLABEL([],[],'demo') shows a demo figure.
matthiasm@8 13 %
matthiasm@8 14 % Known deficiencies: if tick labels are raised to a power, the power
matthiasm@8 15 % will be lost after rotation.
matthiasm@8 16 %
matthiasm@8 17 % See also datetick.
matthiasm@8 18
matthiasm@8 19 % Written Oct 14, 2005 by Andy Bliss
matthiasm@8 20 % Copyright 2005 by Andy Bliss
matthiasm@8 21
matthiasm@8 22 %DEMO:
matthiasm@8 23 if nargin==3
matthiasm@8 24 x=[now-.7 now-.3 now];
matthiasm@8 25 y=[20 35 15];
matthiasm@8 26 figure
matthiasm@8 27 plot(x,y,'.-')
matthiasm@8 28 datetick('x',0,'keepticks')
matthiasm@8 29 h=gca;
matthiasm@8 30 set(h,'position',[0.13 0.35 0.775 0.55])
matthiasm@8 31 rot=90;
matthiasm@8 32 end
matthiasm@8 33
matthiasm@8 34 %set the default rotation if user doesn't specify
matthiasm@8 35 if nargin==1
matthiasm@8 36 rot=90;
matthiasm@8 37 end
matthiasm@8 38 %make sure the rotation is in the range 0:360 (brute force method)
matthiasm@8 39 while rot>360
matthiasm@8 40 rot=rot-360;
matthiasm@8 41 end
matthiasm@8 42 while rot<0
matthiasm@8 43 rot=rot+360;
matthiasm@8 44 end
matthiasm@8 45 %get current tick labels
matthiasm@8 46 a=get(h,'XTickLabel');
matthiasm@8 47 %erase current tick labels from figure
matthiasm@8 48 set(h,'XTickLabel',[]);
matthiasm@8 49 %get tick label positions
matthiasm@8 50 b=get(h,'XTick');
matthiasm@8 51 c=get(h,'YTick');
matthiasm@8 52 %make new tick labels
matthiasm@8 53 if rot<180
matthiasm@8 54 th=text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','right','rotation',rot);
matthiasm@8 55 else
matthiasm@8 56 th=text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','left','rotation',rot);
matthiasm@8 57 end
matthiasm@8 58