changelog shortlog tags changeset files revisions annotate raw

scripts/plot/hold.m

changeset 10289: 4b124317dc38
parent:0307f5e5568c
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (66 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 2005, 2006, 2007, 2008, 2009 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} {} hold
21## @deftypefnx {Function File} {} hold @var{state}
22## @deftypefnx {Function File} {} hold (@var{hax}, @dots{})
23## Toggle or set the 'hold' state of the plotting engine which determines
24## whether new graphic objects are added to the plot or replace the existing
25## objects.
26##
27## @table @code
28## @item hold on
29## Retain plot data and settings so that subsequent plot commands are displayed
30## on a single graph.
31##
32## @item hold off
33## Clear plot and restore default graphics settings before each new plot
34## command. (default).
35##
36## @item hold
37## Toggle the current 'hold' state.
38## @end table
39##
40## When given the additional argument @var{hax}, the hold state is modified
41## only for the given axis handle.
42##
43## To query the current 'hold' state use the @code{ishold} function.
44## @seealso{ishold, cla, newplot, clf}
45## @end deftypefn
46
47function hold (varargin)
48
49 if (nargin > 0 && numel (varargin{1}) == 1 && ishandle (varargin{1})
50 && strcmp (get (varargin{1}, "type"), "axes"))
51 [ax, varargin, nargs] = __plt_get_axis_arg__ ("hold", varargin{:});
52 elseif (nargin > 0 && numel (varargin{1}) > 1 && ishandle (varargin{1}))
53 print_usage ();
54 else
55 ax = gca ();
56 fig = gcf ();
57 nargs = numel (varargin);
58 endif
59
60 if (nargs == 0)
61 turn_hold_off = ishold (ax);
62 elseif (nargs == 1)
63 state = varargin{1};
64 if (ischar (state))
65 if (strcmpi (state, "off"))
66 turn_hold_off = true;
67 elseif (strcmpi (state, "on"))
68 turn_hold_off = false;
69 else
70 error ("hold: invalid hold state");
71 endif
72 endif
73 else
74 print_usage ();
75 endif
76
77 if (turn_hold_off)
78 set (ax, "nextplot", "replace");
79 else
80 set (ax, "nextplot", "add");
81 set (fig, "nextplot", "add");
82 endif
83
84endfunction
85
86%!demo
87%! clf
88%! A = rand (100);
89%! [X, Y] = find (A > 0.9);
90%! imshow (A)
91%! hold on
92%! plot (X, Y, 'o')
93%! hold off
94
95%!demo
96%! clf
97%! hold on
98%! imagesc(1./hilb(4));
99%! plot (1:4, "-s")
100%! hold off
101
102%!demo
103%! clf
104%! hold on
105%! imagesc(1./hilb(2));
106%! imagesc(1./hilb(4));
107%! hold off
108
109%!demo
110%! clf
111%! hold on
112%! plot (1:4, "-s")
113%! imagesc(1./hilb(4));
114%! hold off
115
116%!demo
117%! clf
118%! colormap (jet)
119%! t = linspace (-3, 3, 50);
120%! [x, y] = meshgrid (t, t);
121%! z = peaks (x, y);
122%! contourf (x, y, z, 10);
123%! hold ("on");
124%! plot (vec (x), vec (y), "^");
125%! patch ([-1.0 1.0 1.0 -1.0 -1.0], [-1.0 -1.0 1.0 1.0 -1.0], "red");
126%! xlim ([-2.0 2.0]);
127%! ylim ([-2.0 2.0]);
128%! colorbar ("SouthOutside");
129%! title ("Test script for some plot functions");
130