source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/lightspeed/graphics/axis_pct.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1function ax = axis_pct(pct)
2% AXIS_PCT       Set reasonable axis limits.
3%
4% AXIS_PCT(pct) sets axis limits to extend pct% beyond limits of plotted
5% objects.  Default is 5%.
6% Works for linear or log scale.
7% Unfortunately, the axes won't change when new points are plotted.
8
9% Written by Tom Minka
10
11if nargin < 1
12  pct = 0.05;
13end
14ax = [Inf -Inf Inf -Inf Inf -Inf];
15
16% find bounding box of plotted objects
17children = get(gca,'children');
18for child = children'
19  if strcmp(get(child,'type'),'text')
20    xyz = get(child,'position');
21    % need to determine bounding box of the text
22    if strcmp(get(gca,'xscale'), 'log')
23      xyz(1) = log10(xyz(1));
24    end
25    if strcmp(get(gca,'yscale'), 'log')
26      xyz(2) = log10(xyz(2));
27    end
28    if strcmp(get(gca,'zscale'), 'log')
29      xyz(3) = log10(xyz(3));
30    end
31    c([1 2]) = xyz(1);
32    c([3 4]) = xyz(2);
33    c([5 6]) = xyz(3);
34  else
35    x = get(child,'xdata');
36    x = x(finite(x));
37    if strcmp(get(gca,'xscale'), 'log')
38      x = x(x > 0);
39      x = log10(x);
40    end
41    if isempty(x)
42      c([1 2]) = 0;
43    else
44      c([1 2]) = [min(x(:)) max(x(:))];
45    end
46    y = get(child,'ydata');
47    y = y(finite(y));
48    if strcmp(get(gca,'yscale'), 'log')
49      y = y(y > 0);
50      y = log10(y);
51    end
52    if isempty(y)
53      c([3 4]) = 0;
54    else
55      c([3 4]) = [min(y(:)) max(y(:))];
56    end
57    try
58      z = get(child,'zdata');
59      z = z(finite(z));
60      if isempty(z)
61        c([5 6]) = 0;
62      else
63        if strcmp(get(gca,'zscale'), 'log')
64          z = z(z > 0);
65          z = log10(z);
66        end
67        c([5 6]) = [min(z(:)) max(z(:))];
68      end
69    end
70  end
71  ax([1 3 5]) = min(ax([1 3 5]), c([1 3 5]));
72  ax([2 4 6]) = max(ax([2 4 6]), c([2 4 6]));
73end
74dx = ax(2)-ax(1);
75if dx == 0
76  dx = 1;
77end
78dy = ax(4)-ax(3);
79if dy == 0
80  dy = 1;
81end
82dz = ax(6)-ax(5);
83if dz == 0
84  dz = 1;
85end
86ax = ax + [-dx dx -dy dy -dz dz]*pct;
87if strcmp(get(gca,'xscale'), 'log')
88  ax([1 2]) = 10.^(ax([1 2]));
89end
90if strcmp(get(gca,'yscale'), 'log')
91  ax([3 4]) = 10.^(ax([3 4]));
92end
93if strcmp(get(gca,'zscale'), 'log')
94  ax([5 6]) = 10.^(ax([5 6]));
95end
96% clip for 2D
97ax = ax(1:length(axis));
98if ~isempty(children)
99  axis(ax);
100end
101if nargout < 1
102  clear ax
103end
Note: See TracBrowser for help on using the repository browser.