comparison toolboxes/FullBNT-1.0.7/KPMtools/axis_pct.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 ax = axis_pct(pct)
2 % AXIS_PCT Set reasonable axis limits.
3 % AXIS_PCT(pct) sets axis limits to extend pct% beyond limits of plotted
4 % objects. Default is 5%.
5 % Works for linear or log scale.
6 % Unfortunately, the axes won't change when new points are plotted.
7
8 if nargin < 1
9 pct = 0.05;
10 end
11 ax = [Inf -Inf Inf -Inf Inf -Inf];
12
13 % find bounding box of plotted objects
14 children = get(gca,'children');
15 for child = children'
16 if strcmp(get(child,'type'),'text')
17 xyz = get(child,'position');
18 % need to determine bounding box of the text
19 c([1 2]) = xyz(1);
20 c([3 4]) = xyz(2);
21 c([5 6]) = xyz(3);
22 else
23 x = get(child,'xdata');
24 c(1) = min(x);
25 c(2) = max(x);
26 y = get(child,'ydata');
27 c(3) = min(y);
28 c(4) = max(y);
29 z = get(child,'zdata');
30 if isempty(z)
31 c([5 6]) = 0;
32 else
33 c(5) = min(z);
34 c(6) = max(z);
35 end
36 end
37 ax([1 3 5]) = min(ax([1 3 5]), c([1 3 5]));
38 ax([2 4 6]) = max(ax([2 4 6]), c([2 4 6]));
39 end
40 if strcmp(get(gca,'xscale'), 'log')
41 ax([1 2]) = log(ax([1 2]));
42 end
43 if strcmp(get(gca,'yscale'), 'log')
44 ax([3 4]) = log(ax([3 4]));
45 end
46 dx = ax(2)-ax(1);
47 if dx == 0
48 dx = 1;
49 end
50 dy = ax(4)-ax(3);
51 if dy == 0
52 dy = 1;
53 end
54 dz = ax(6)-ax(5);
55 if dz == 0
56 dz = 1;
57 end
58 ax = ax + [-dx dx -dy dy -dz dz]*pct;
59 if strcmp(get(gca,'xscale'), 'log')
60 ax([1 2]) = exp(ax([1 2]));
61 end
62 if strcmp(get(gca,'yscale'), 'log')
63 ax([3 4]) = exp(ax([3 4]));
64 end
65 % clip for 2D
66 ax = ax(1:length(axis));
67 axis(ax);
68 if nargout < 1
69 clear ax
70 end