]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/newplot.m
update packages
[CreaPhase.git] / octave_packages / m / plot / newplot.m
1 ## Copyright (C) 2005-2012 John W. Eaton
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} {} newplot ()
21 ## Prepare graphics engine to produce a new plot.  This function is
22 ## called at the beginning of all high-level plotting functions.
23 ## It is not normally required in user programs.
24 ## @end deftypefn
25
26 function newplot ()
27
28   if (nargin == 0)
29     cf = gcf ();
30     fnp = get (cf, "nextplot");
31     switch (fnp)
32       ## FIXME -- probably we should do more than validate the nextplot
33       ## property value...
34       case "new"
35       case "add"
36       case "replacechildren"
37         delete (get (cf, "children"));
38       case "replace"
39       otherwise
40         error ("newplot: unrecognized nextplot property for current figure");
41     endswitch
42     ca = gca ();
43     anp = get (ca, "nextplot");
44     if (strcmp (get (ca, "__hold_all__"), "off"))
45       __next_line_color__ (true);
46       __next_line_style__ (true);
47     else
48       __next_line_color__ (false);
49       __next_line_style__ (false);
50     endif
51     switch (anp)
52       case "new"
53       case "add"
54       case "replacechildren"
55         delete (get (ca, "children"));
56       case "replace"
57         __go_axes_init__ (ca, "replace");
58         __request_drawnow__ ();
59       otherwise
60         error ("newplot: unrecognized nextplot property for current axes");
61     endswitch
62   else
63     print_usage ();
64   endif
65
66 endfunction
67
68 %!test
69 %! hf = figure ("visible", "off");
70 %! unwind_protect
71 %!   p = plot ([0, 1]);
72 %!   newplot;
73 %!   assert (isempty (get (gca, "children")));
74 %! unwind_protect_cleanup
75 %!   close (hf);
76 %! end_unwind_protect