comparison scripts/plot/pareto.m @ 11587:c792872f8942

all script files: untabify and strip trailing whitespace
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:35:29 -0500
parents fd0a3ac60b0e
children cefd568ea073
comparison
equal deleted inserted replaced
11586:12df7854fa7c 11587:c792872f8942
20 ## -*- texinfo -*- 20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {} pareto (@var{x}) 21 ## @deftypefn {Function File} {} pareto (@var{x})
22 ## @deftypefnx {Function File} {} pareto (@var{x}, @var{y}) 22 ## @deftypefnx {Function File} {} pareto (@var{x}, @var{y})
23 ## @deftypefnx {Function File} {} pareto (@var{h}, @dots{}) 23 ## @deftypefnx {Function File} {} pareto (@var{h}, @dots{})
24 ## @deftypefnx {Function File} {@var{h} =} pareto (@dots{}) 24 ## @deftypefnx {Function File} {@var{h} =} pareto (@dots{})
25 ## Draw a Pareto chart, also called ABC chart. A Pareto chart is a bar graph 25 ## Draw a Pareto chart, also called ABC chart. A Pareto chart is a bar graph
26 ## used to arrange information in such a way that priorities for process 26 ## used to arrange information in such a way that priorities for process
27 ## improvement can be established. It organizes and displays information 27 ## improvement can be established. It organizes and displays information
28 ## to show the relative importance of data. The chart is similar to the 28 ## to show the relative importance of data. The chart is similar to the
29 ## histogram or bar chart, except that the bars are arranged in decreasing 29 ## histogram or bar chart, except that the bars are arranged in decreasing
30 ## order from left to right along the abscissa. 30 ## order from left to right along the abscissa.
31 ## 31 ##
32 ## The fundamental idea (Pareto principle) behind the use of Pareto 32 ## The fundamental idea (Pareto principle) behind the use of Pareto
33 ## diagrams is that the majority of an effect is due to a small subset of the 33 ## diagrams is that the majority of an effect is due to a small subset of the
34 ## causes, so for quality improvement the first few (as presented on the 34 ## causes, so for quality improvement the first few (as presented on the
35 ## diagram) contributing causes to a problem usually account for the majority 35 ## diagram) contributing causes to a problem usually account for the majority
36 ## of the result. Thus, targeting these "major causes" for elimination 36 ## of the result. Thus, targeting these "major causes" for elimination
37 ## results in the most cost-effective improvement scheme. 37 ## results in the most cost-effective improvement scheme.
38 ## 38 ##
39 ## The data are passed as @var{x} and the abscissa as @var{y}. If @var{y} is 39 ## The data are passed as @var{x} and the abscissa as @var{y}. If @var{y} is
40 ## absent, then the abscissa are assumed to be @code{1 : length (@var{x})}. 40 ## absent, then the abscissa are assumed to be @code{1 : length (@var{x})}.
41 ## @var{y} can be a string array, a cell array of strings or a numerical 41 ## @var{y} can be a string array, a cell array of strings or a numerical
68 else 68 else
69 y = cellfun (@num2str, num2cell (y), "uniformoutput", false); 69 y = cellfun (@num2str, num2cell (y), "uniformoutput", false);
70 endif 70 endif
71 endif 71 endif
72 else 72 else
73 y = cellfun (@int2str, num2cell (1 : numel(x)), 73 y = cellfun (@int2str, num2cell (1 : numel(x)),
74 "uniformoutput", false); 74 "uniformoutput", false);
75 endif 75 endif
76 76
77 [x, idx] = sort (x, "descend"); 77 [x, idx] = sort (x, "descend");
78 y = y (idx); 78 y = y (idx);
80 maxcdf = max(cdf); 80 maxcdf = max(cdf);
81 cdf = cdf ./ maxcdf; 81 cdf = cdf ./ maxcdf;
82 cdf95 = cdf - 0.95; 82 cdf95 = cdf - 0.95;
83 idx95 = find(sign(cdf95(1:end-1)) != sign(cdf95(2:end)))(1); 83 idx95 = find(sign(cdf95(1:end-1)) != sign(cdf95(2:end)))(1);
84 84
85 [ax, hbar, hline] = plotyy (1 : idx95, x (1 : idx95), 85 [ax, hbar, hline] = plotyy (1 : idx95, x (1 : idx95),
86 1 : length(cdf), 100 .* cdf, 86 1 : length(cdf), 100 .* cdf,
87 @bar, @plot); 87 @bar, @plot);
88 88
89 axis (ax(1), [1 - 0.6, idx95 + 0.6, 0, maxcdf]); 89 axis (ax(1), [1 - 0.6, idx95 + 0.6, 0, maxcdf]);
90 axis (ax(2), [1 - 0.6, idx95 + 0.6, 0, 100]); 90 axis (ax(2), [1 - 0.6, idx95 + 0.6, 0, 100]);
91 set (ax(2), "ytick", [0, 20, 40, 60, 80, 100], 91 set (ax(2), "ytick", [0, 20, 40, 60, 80, 100],
92 "yticklabel", {"0%", "20%", "40%", "60%", "80%", "100%"}); 92 "yticklabel", {"0%", "20%", "40%", "60%", "80%", "100%"});
93 set (ax(1), "xtick", 1 : idx95, "xticklabel", y (1: idx95)); 93 set (ax(1), "xtick", 1 : idx95, "xticklabel", y (1: idx95));
94 set (ax(2), "xtick", 1 : idx95, "xticklabel", y (1: idx95)); 94 set (ax(2), "xtick", 1 : idx95, "xticklabel", y (1: idx95));
95 95
96 if (nargout > 0) 96 if (nargout > 0)
97 h = [hbar; hline]; 97 h = [hbar; hline];
98 endif 98 endif
99 99
100 endfunction 100 endfunction
101 101
102 %!demo 102 %!demo
103 %! clf 103 %! clf
104 %! colormap (jet (64)) 104 %! colormap (jet (64))