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