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