Home > utils > rotateticklabel.m

rotateticklabel

PURPOSE ^

ROTATETICKLABEL rotates tick labels

SYNOPSIS ^

function th=rotateticklabel(h,rot,demo)

DESCRIPTION ^

ROTATETICKLABEL rotates tick labels
   TH=ROTATETICKLABEL(H,ROT) is the calling form where H is a handle to
   the axis that contains the XTickLabels that are to be rotated. ROT is
   an optional parameter that specifies the angle of rotation. The default
   angle is 90. TH is a handle to the text objects created. For long
   strings such as those produced by datetick, you may have to adjust the
   position of the axes so the labels don't get cut off.

   Of course, GCA can be substituted for H if desired.

   TH=ROTATETICKLABEL([],[],'demo') shows a demo figure.

   Known deficiencies: if tick labels are raised to a power, the power
   will be lost after rotation.

   See also datetick.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function th=rotateticklabel(h,rot,demo)
0002 %ROTATETICKLABEL rotates tick labels
0003 %   TH=ROTATETICKLABEL(H,ROT) is the calling form where H is a handle to
0004 %   the axis that contains the XTickLabels that are to be rotated. ROT is
0005 %   an optional parameter that specifies the angle of rotation. The default
0006 %   angle is 90. TH is a handle to the text objects created. For long
0007 %   strings such as those produced by datetick, you may have to adjust the
0008 %   position of the axes so the labels don't get cut off.
0009 %
0010 %   Of course, GCA can be substituted for H if desired.
0011 %
0012 %   TH=ROTATETICKLABEL([],[],'demo') shows a demo figure.
0013 %
0014 %   Known deficiencies: if tick labels are raised to a power, the power
0015 %   will be lost after rotation.
0016 %
0017 %   See also datetick.
0018 
0019 %   Written Oct 14, 2005 by Andy Bliss
0020 %   Copyright 2005 by Andy Bliss
0021 
0022 %DEMO:
0023 if nargin==3
0024     x=[now-.7 now-.3 now];
0025     y=[20 35 15];
0026     figure
0027     plot(x,y,'.-')
0028     datetick('x',0,'keepticks')
0029     h=gca;
0030     set(h,'position',[0.13 0.35 0.775 0.55])
0031     rot=90;
0032 end
0033 
0034 %set the default rotation if user doesn't specify
0035 if nargin==1
0036     rot=90;
0037 end
0038 %make sure the rotation is in the range 0:360 (brute force method)
0039 while rot>360
0040     rot=rot-360;
0041 end
0042 while rot<0
0043     rot=rot+360;
0044 end
0045 %get current tick labels
0046 a=get(h,'XTickLabel');
0047 %erase current tick labels from figure
0048 set(h,'XTickLabel',[]);
0049 %get tick label positions
0050 b=get(h,'XTick');
0051 c=get(h,'YTick');
0052 %make new tick labels
0053 if rot<180
0054     th=text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','right','rotation',rot);
0055 else
0056     th=text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','left','rotation',rot);
0057 end
0058

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003