]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/pie.m
update packages
[CreaPhase.git] / octave_packages / m / plot / pie.m
1 ## Copyright (C) 2007-2012 David Bateman
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn  {Function File} {} pie (@var{x})
21 ## @deftypefnx {Function File} {} pie (@var{x}, @var{explode})
22 ## @deftypefnx {Function File} {} pie (@dots{}, @var{labels})
23 ## @deftypefnx {Function File} {} pie (@var{h}, @dots{});
24 ## @deftypefnx {Function File} {@var{h} =} pie (@dots{});
25 ## Produce a 2-D pie chart.
26 ##
27 ## Called with a single vector argument, produces a pie chart of the
28 ## elements in @var{x}, with the size of the slice determined by percentage
29 ## size of the values of @var{x}.
30 ##
31 ## The variable @var{explode} is a vector of the same length as @var{x} that
32 ## if non zero 'explodes' the slice from the pie chart.
33 ##
34 ## If given @var{labels} is a cell array of strings of the same length as
35 ## @var{x}, giving the labels of each of the slices of the pie chart.
36 ##
37 ## The optional return value @var{h} is a list of handles to the patch
38 ## and text objects generating the plot.
39 ##
40 ## @seealso{pie3, bar, stem}
41 ## @end deftypefn
42
43 ## Very roughly based on pie.m from octave-forge whose author was
44 ## Daniel Heiserer <Daniel.heiserer@physik.tu-muenchen.de>
45
46 function retval = pie (varargin)
47
48   [h, varargin] = __plt_get_axis_arg__ ("pie", varargin{:});
49
50   if (nargin < 1)
51     print_usage ();
52   else
53     oldh = gca ();
54     unwind_protect
55       axes (h);
56       newplot ();
57       tmp = __pie__ ("pie", h, varargin{:});
58     unwind_protect_cleanup
59       axes (oldh);
60     end_unwind_protect
61   endif
62
63   if (nargout > 0)
64     retval = tmp;
65   endif
66
67 endfunction
68
69
70 %!demo
71 %! clf
72 %! pie ([3, 2, 1], [0, 0, 1]);
73 %! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
74
75 %!demo
76 %! clf
77 %! pie ([3, 2, 1], [0, 0, 1], {"Cheddar", "Swiss", "Camembert"});
78 %! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
79 %! axis ([-2,2,-2,2]);
80
81 %!demo
82 %! clf
83 %! pie ([0.17, 0.34, 0.41], {"Cheddar", "Swiss", "Camembert"});
84 %! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
85 %! axis ([-2,2,-2,2]);
86 %! title ("missing slice");
87