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