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