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