annotate _FullBNT/KPMtools/axis_pct.m @ 9:4ea6619cb3f5 tip

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