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