annotate toolboxes/FullBNT-1.0.7/KPMtools/set_xtick_label.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function set_xtick_label(tick_labels, angle, axis_label)
wolffd@0 2 % SET_XTICK_LABEL Print the xtick labels at an angle instead of horizontally
wolffd@0 3 % set_xtick_label(tick_labels, angle, axis_label)
wolffd@0 4 %
wolffd@0 5 % angle default = 90
wolffd@0 6 % axis_label default = ''
wolffd@0 7 %
wolffd@0 8 % This is derived from Solution Number: 5375 on mathworks.com
wolffd@0 9 % See set_xtick_label_demo for an example
wolffd@0 10
wolffd@0 11 if nargin < 2, angle = 90; end
wolffd@0 12 if nargin < 3, axis_label = []; end
wolffd@0 13
wolffd@0 14 % Reduce the size of the axis so that all the labels fit in the figure.
wolffd@0 15 pos = get(gca,'Position');
wolffd@0 16 %set(gca,'Position',[pos(1), .2, pos(3) .65])
wolffd@0 17 %set(gca,'Position',[pos(1), 0, pos(3) .45])
wolffd@0 18 %set(gca,'Position',[pos(1), 0.1, pos(3) 0.5])
wolffd@0 19
wolffd@0 20 ax = axis; % Current axis limits
wolffd@0 21 axis(axis); % Fix the axis limits
wolffd@0 22 Yl = ax(3:4); % Y-axis limits
wolffd@0 23
wolffd@0 24 %set(gca, 'xtick', 1:length(tick_labels));
wolffd@0 25 set(gca, 'xtick', 0.7:1:length(tick_labels));
wolffd@0 26 Xt = get(gca, 'xtick');
wolffd@0 27
wolffd@0 28 % Place the text labels
wolffd@0 29 t = text(Xt,Yl(1)*ones(1,length(Xt)),tick_labels);
wolffd@0 30 set(t,'HorizontalAlignment','right','VerticalAlignment','top', 'Rotation', angle);
wolffd@0 31
wolffd@0 32 % Remove the default labels
wolffd@0 33 set(gca,'XTickLabel','')
wolffd@0 34
wolffd@0 35 % Get the Extent of each text object. This
wolffd@0 36 % loop is unavoidable.
wolffd@0 37 for i = 1:length(t)
wolffd@0 38 ext(i,:) = get(t(i),'Extent');
wolffd@0 39 end
wolffd@0 40
wolffd@0 41 % Determine the lowest point. The X-label will be
wolffd@0 42 % placed so that the top is aligned with this point.
wolffd@0 43 LowYPoint = min(ext(:,2));
wolffd@0 44
wolffd@0 45 % Place the axis label at this point
wolffd@0 46 if ~isempty(axis_label)
wolffd@0 47 Xl = get(gca, 'Xlim');
wolffd@0 48 XMidPoint = Xl(1)+abs(diff(Xl))/2;
wolffd@0 49 tl = text(XMidPoint,LowYPoint, axis_label, 'VerticalAlignment','top', ...
wolffd@0 50 'HorizontalAlignment','center');
wolffd@0 51 end