Daniel@0: function xticklabel_rotate90(XTick,varargin) Daniel@0: %XTICKLABEL_ROTATE90 - Rotate numeric Xtick labels by 90 degrees Daniel@0: % Daniel@0: % Syntax: xticklabel_rotate90(XTick) Daniel@0: % Daniel@0: % Input: XTick - vector array of XTick positions & values (numeric) Daniel@0: % Daniel@0: % Output: none Daniel@0: % Daniel@0: % Example 1: Set the positions of the XTicks and rotate them Daniel@0: % figure; plot([1960:2004],randn(45,1)); xlim([1960 2004]); Daniel@0: % xticklabel_rotate90([1960:2:2004]); Daniel@0: % %If you wish, you may set a few text "Property-value" pairs Daniel@0: % xticklabel_rotate90([1960:2:2004],'Color','m','Fontweight','bold'); Daniel@0: % Daniel@0: % Example 2: %Rotate XTickLabels at their current position Daniel@0: % XTick = get(gca,'XTick'); Daniel@0: % xticklabel_rotate90(XTick); Daniel@0: % Daniel@0: % Other m-files required: none Daniel@0: % Subfunctions: none Daniel@0: % MAT-files required: none Daniel@0: % Daniel@0: % See also: TEXT, SET Daniel@0: Daniel@0: % Author: Denis Gilbert, Ph.D., physical oceanography Daniel@0: % Maurice Lamontagne Institute, Dept. of Fisheries and Oceans Canada Daniel@0: % email: gilbertd@dfo-mpo.gc.ca Web: http://www.qc.dfo-mpo.gc.ca/iml/ Daniel@0: % February 1998; Last revision: 24-Mar-2003 Daniel@0: Daniel@0: if ~isnumeric(XTick) Daniel@0: error('XTICKLABEL_ROTATE90 requires a numeric input argument'); Daniel@0: end Daniel@0: Daniel@0: %Make sure XTick is a column vector Daniel@0: XTick = XTick(:); Daniel@0: Daniel@0: %Set the Xtick locations and set XTicklabel to an empty string Daniel@0: set(gca,'XTick',XTick,'XTickLabel','') Daniel@0: Daniel@0: % Define the xtickLabels Daniel@0: xTickLabels = num2str(XTick); Daniel@0: Daniel@0: % Determine the location of the labels based on the position Daniel@0: % of the xlabel Daniel@0: hxLabel = get(gca,'XLabel'); % Handle to xlabel Daniel@0: xLabelString = get(hxLabel,'String'); Daniel@0: Daniel@0: if ~isempty(xLabelString) Daniel@0: warning('You may need to manually reset the XLABEL vertical position') Daniel@0: end Daniel@0: Daniel@0: set(hxLabel,'Units','data'); Daniel@0: xLabelPosition = get(hxLabel,'Position'); Daniel@0: y = xLabelPosition(2); Daniel@0: Daniel@0: %CODE below was modified following suggestions from Urs Schwarz Daniel@0: y=repmat(y,size(XTick,1),1); Daniel@0: % retrieve current axis' fontsize Daniel@0: fs = get(gca,'fontsize'); Daniel@0: Daniel@0: % Place the new xTickLabels by creating TEXT objects Daniel@0: hText = text(XTick, y, xTickLabels,'fontsize',fs); Daniel@0: Daniel@0: % Rotate the text objects by 90 degrees Daniel@0: set(hText,'Rotation',90,'HorizontalAlignment','right',varargin{:}) Daniel@0: Daniel@0: %------------- END OF CODE --------------