annotate scripts/plot/pie3.m @ 11330:4f399d91eb32

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