comparison toolboxes/FullBNT-1.0.7/KPMtools/xticklabel_rotate90.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function xticklabel_rotate90(XTick,varargin)
2 %XTICKLABEL_ROTATE90 - Rotate numeric Xtick labels by 90 degrees
3 %
4 % Syntax: xticklabel_rotate90(XTick)
5 %
6 % Input: XTick - vector array of XTick positions & values (numeric)
7 %
8 % Output: none
9 %
10 % Example 1: Set the positions of the XTicks and rotate them
11 % figure; plot([1960:2004],randn(45,1)); xlim([1960 2004]);
12 % xticklabel_rotate90([1960:2:2004]);
13 % %If you wish, you may set a few text "Property-value" pairs
14 % xticklabel_rotate90([1960:2:2004],'Color','m','Fontweight','bold');
15 %
16 % Example 2: %Rotate XTickLabels at their current position
17 % XTick = get(gca,'XTick');
18 % xticklabel_rotate90(XTick);
19 %
20 % Other m-files required: none
21 % Subfunctions: none
22 % MAT-files required: none
23 %
24 % See also: TEXT, SET
25
26 % Author: Denis Gilbert, Ph.D., physical oceanography
27 % Maurice Lamontagne Institute, Dept. of Fisheries and Oceans Canada
28 % email: gilbertd@dfo-mpo.gc.ca Web: http://www.qc.dfo-mpo.gc.ca/iml/
29 % February 1998; Last revision: 24-Mar-2003
30
31 if ~isnumeric(XTick)
32 error('XTICKLABEL_ROTATE90 requires a numeric input argument');
33 end
34
35 %Make sure XTick is a column vector
36 XTick = XTick(:);
37
38 %Set the Xtick locations and set XTicklabel to an empty string
39 set(gca,'XTick',XTick,'XTickLabel','')
40
41 % Define the xtickLabels
42 xTickLabels = num2str(XTick);
43
44 % Determine the location of the labels based on the position
45 % of the xlabel
46 hxLabel = get(gca,'XLabel'); % Handle to xlabel
47 xLabelString = get(hxLabel,'String');
48
49 if ~isempty(xLabelString)
50 warning('You may need to manually reset the XLABEL vertical position')
51 end
52
53 set(hxLabel,'Units','data');
54 xLabelPosition = get(hxLabel,'Position');
55 y = xLabelPosition(2);
56
57 %CODE below was modified following suggestions from Urs Schwarz
58 y=repmat(y,size(XTick,1),1);
59 % retrieve current axis' fontsize
60 fs = get(gca,'fontsize');
61
62 % Place the new xTickLabels by creating TEXT objects
63 hText = text(XTick, y, xTickLabels,'fontsize',fs);
64
65 % Rotate the text objects by 90 degrees
66 set(hText,'Rotation',90,'HorizontalAlignment','right',varargin{:})
67
68 %------------- END OF CODE --------------