annotate toolboxes/FullBNT-1.0.7/KPMtools/xticklabel_rotate90.m @ 0:cc4b1211e677 tip

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