Mercurial > hg > octave-nkf
comparison scripts/plot/pareto.m @ 17160:6e8c621c3496
pareto.m: Accept an axis handle as first input.
* scripts/plot/pareto.m: Use __plt_axis_get_arg__ to accept an axis handle as
first input.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 02 Aug 2013 17:35:52 -0700 |
parents | eaab03308c0b |
children | bc924baa2c4e |
comparison
equal
deleted
inserted
replaced
17159:d74e2b5bdeb5 | 17160:6e8c621c3496 |
---|---|
62 ## @seealso{bar, barh, hist, pie, plot} | 62 ## @seealso{bar, barh, hist, pie, plot} |
63 ## @end deftypefn | 63 ## @end deftypefn |
64 | 64 |
65 function h = pareto (varargin) | 65 function h = pareto (varargin) |
66 | 66 |
67 [hax, varargin, nargin] = __plt_get_axis_arg__ ("pareto", varargin{:}); | |
68 | |
67 if (nargin != 1 && nargin != 2) | 69 if (nargin != 1 && nargin != 2) |
68 print_usage (); | 70 print_usage (); |
69 endif | 71 endif |
70 | 72 |
71 x = varargin {1}(:).'; | 73 x = varargin {1}(:).'; |
82 y = cellfun ("int2str", num2cell (1 : numel (x)), | 84 y = cellfun ("int2str", num2cell (1 : numel (x)), |
83 "uniformoutput", false); | 85 "uniformoutput", false); |
84 endif | 86 endif |
85 | 87 |
86 [x, idx] = sort (x, "descend"); | 88 [x, idx] = sort (x, "descend"); |
87 y = y (idx); | 89 y = y(idx); |
88 cdf = cumsum (x); | 90 cdf = cumsum (x); |
89 maxcdf = max (cdf); | 91 maxcdf = max (cdf); |
90 cdf = cdf ./ maxcdf; | 92 cdf = cdf ./ maxcdf; |
91 cdf95 = cdf - 0.95; | 93 cdf95 = cdf - 0.95; |
92 idx95 = find (sign (cdf95(1:end-1)) != sign (cdf95(2:end)))(1); | 94 idx95 = find (sign (cdf95(1:end-1)) != sign (cdf95(2:end)))(1); |
93 | 95 |
94 [ax, hbar, hline] = plotyy (1 : idx95, x (1 : idx95), | 96 if (isempty (hax)) |
95 1 : length (cdf), 100 .* cdf, | 97 [ax, hbar, hline] = plotyy (1 : idx95, x (1 : idx95), |
96 @bar, @plot); | 98 1 : length (cdf), 100 .* cdf, |
99 @bar, @plot); | |
100 else | |
101 [ax, hbar, hline] = plotyy (hax, 1 : idx95, x (1 : idx95), | |
102 1 : length (cdf), 100 .* cdf, | |
103 @bar, @plot); | |
104 endif | |
97 | 105 |
98 axis (ax(1), [1 - 0.6, idx95 + 0.6, 0, maxcdf]); | 106 axis (ax(1), [1 - 0.6, idx95 + 0.6, 0, maxcdf]); |
99 axis (ax(2), [1 - 0.6, idx95 + 0.6, 0, 100]); | 107 axis (ax(2), [1 - 0.6, idx95 + 0.6, 0, 100]); |
100 set (ax(2), "ytick", [0, 20, 40, 60, 80, 100], | 108 set (ax(2), "ytick", [0, 20, 40, 60, 80, 100], |
101 "yticklabel", {"0%", "20%", "40%", "60%", "80%", "100%"}); | 109 "yticklabel", {"0%", "20%", "40%", "60%", "80%", "100%"}); |
102 set (ax(1), "xtick", 1 : idx95, "xticklabel", y (1: idx95)); | 110 set (ax(1), "xtick", 1:idx95, "xticklabel", y(1:idx95)); |
103 set (ax(2), "xtick", 1 : idx95, "xticklabel", y (1: idx95)); | 111 set (ax(2), "xtick", 1:idx95, "xticklabel", y(1:idx95)); |
104 | 112 |
105 if (nargout > 0) | 113 if (nargout > 0) |
106 h = [hbar; hline]; | 114 h = [hbar; hline]; |
107 endif | 115 endif |
108 | 116 |