Mercurial > hg > octave-nkf
annotate scripts/plot/hold.m @ 9272:3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Tue, 26 May 2009 21:16:54 -0400 |
parents | eb63fbe60fab |
children | c539ec5726e7 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2005, 2006, 2007, 2008, 2009 John W. Eaton |
5406 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5406 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5406 | 18 |
19 ## -*- texinfo -*- | |
6713 | 20 ## @deftypefn {Function File} {} hold @var{args} |
7985
85c5c1d55820
hold.m: Trival mod to help text.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
21 ## Tell Octave to `hold' the current data on the graph when executing |
5406 | 22 ## subsequent plotting commands. This allows you to execute a series of |
7985
85c5c1d55820
hold.m: Trival mod to help text.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
23 ## plot commands and have all the lines end up on the same graph. The |
5406 | 24 ## default is for each new plot command to clear the plot device first. |
25 ## For example, the command | |
26 ## | |
27 ## @example | |
28 ## hold on | |
29 ## @end example | |
30 ## | |
31 ## @noindent | |
32 ## turns the hold state on. An argument of @code{"off"} turns the hold | |
33 ## state off, and @code{hold} with no arguments toggles the current hold | |
34 ## state. | |
7985
85c5c1d55820
hold.m: Trival mod to help text.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
35 ## |
85c5c1d55820
hold.m: Trival mod to help text.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
36 ## @deftypefnx {Function File} {} hold (@var{h}, @dots{}) |
85c5c1d55820
hold.m: Trival mod to help text.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
37 ## |
85c5c1d55820
hold.m: Trival mod to help text.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
38 ## Applies to a specific axis or axes, associated with the handle(s), |
85c5c1d55820
hold.m: Trival mod to help text.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
39 ## @var{h}. |
85c5c1d55820
hold.m: Trival mod to help text.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
40 ## |
5406 | 41 ## @end deftypefn |
42 | |
6257 | 43 function hold (varargin) |
5406 | 44 |
8240
5cfeb7bc497a
comet.m,hold.m: validate axes handle
Ben Abbott <bpabbott@mac.com>
parents:
8190
diff
changeset
|
45 if (nargin > 0 && numel (varargin{1}) == 1 && ishandle (varargin{1}(1)) |
5cfeb7bc497a
comet.m,hold.m: validate axes handle
Ben Abbott <bpabbott@mac.com>
parents:
8190
diff
changeset
|
46 && strcmp (get (varargin{1}, "type"), "axes")) |
8065
6333da0dfdfd
hold.m: if hold is applied to a figure, set state for all child axes objects
John W. Eaton <jwe@octave.org>
parents:
7985
diff
changeset
|
47 [h, varargin, nargs] = __plt_get_axis_arg__ ("hold", varargin{:}); |
8189
8e8afefe9466
Remove reliance on ishandle(vec) == false.
Ben Abbott <bpabbott@mac.com>
parents:
8075
diff
changeset
|
48 elseif (nargin > 0 && numel (varargin{1}) > 1 && ishandle (varargin{1}(1))) |
8e8afefe9466
Remove reliance on ishandle(vec) == false.
Ben Abbott <bpabbott@mac.com>
parents:
8075
diff
changeset
|
49 print_usage (); |
8065
6333da0dfdfd
hold.m: if hold is applied to a figure, set state for all child axes objects
John W. Eaton <jwe@octave.org>
parents:
7985
diff
changeset
|
50 else |
6333da0dfdfd
hold.m: if hold is applied to a figure, set state for all child axes objects
John W. Eaton <jwe@octave.org>
parents:
7985
diff
changeset
|
51 h = gcf (); |
6333da0dfdfd
hold.m: if hold is applied to a figure, set state for all child axes objects
John W. Eaton <jwe@octave.org>
parents:
7985
diff
changeset
|
52 nargs = numel (varargin); |
6333da0dfdfd
hold.m: if hold is applied to a figure, set state for all child axes objects
John W. Eaton <jwe@octave.org>
parents:
7985
diff
changeset
|
53 endif |
5406 | 54 |
6257 | 55 hold_state = get (h, "nextplot"); |
5406 | 56 |
6257 | 57 if (nargs == 0) |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
8189
diff
changeset
|
58 if (strcmpi (hold_state, "add")) |
6257 | 59 hold_state = "replace"; |
5406 | 60 else |
6257 | 61 hold_state = "add"; |
62 endif | |
63 elseif (nargs == 1) | |
64 state = varargin{1}; | |
65 if (ischar (state)) | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
8189
diff
changeset
|
66 if (strcmpi (state, "off")) |
6257 | 67 hold_state = "replace"; |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
8189
diff
changeset
|
68 elseif (strcmpi (state, "on")) |
6257 | 69 hold_state = "add"; |
70 else | |
71 print_usage (); | |
72 endif | |
5406 | 73 endif |
74 else | |
6046 | 75 print_usage (); |
5406 | 76 endif |
77 | |
8065
6333da0dfdfd
hold.m: if hold is applied to a figure, set state for all child axes objects
John W. Eaton <jwe@octave.org>
parents:
7985
diff
changeset
|
78 if (isfigure (h)) |
8075
a028a5960e18
Fix for hold with no figures/axes. Set prop/val pairs to hggroups rather than underlying objects. Fix for equality test in array_property
David Bateman <dbateman@free.fr>
parents:
8065
diff
changeset
|
79 if (isempty (get (h, "currentaxes"))) |
a028a5960e18
Fix for hold with no figures/axes. Set prop/val pairs to hggroups rather than underlying objects. Fix for equality test in array_property
David Bateman <dbateman@free.fr>
parents:
8065
diff
changeset
|
80 set (h, "currentaxes", __go_axes__ (h)) |
a028a5960e18
Fix for hold with no figures/axes. Set prop/val pairs to hggroups rather than underlying objects. Fix for equality test in array_property
David Bateman <dbateman@free.fr>
parents:
8065
diff
changeset
|
81 endif |
8065
6333da0dfdfd
hold.m: if hold is applied to a figure, set state for all child axes objects
John W. Eaton <jwe@octave.org>
parents:
7985
diff
changeset
|
82 axes_objs = findobj (h, "type", "axes"); |
6333da0dfdfd
hold.m: if hold is applied to a figure, set state for all child axes objects
John W. Eaton <jwe@octave.org>
parents:
7985
diff
changeset
|
83 h = [h; axes_objs]; |
6333da0dfdfd
hold.m: if hold is applied to a figure, set state for all child axes objects
John W. Eaton <jwe@octave.org>
parents:
7985
diff
changeset
|
84 endif |
6333da0dfdfd
hold.m: if hold is applied to a figure, set state for all child axes objects
John W. Eaton <jwe@octave.org>
parents:
7985
diff
changeset
|
85 |
6257 | 86 set (h, "nextplot", hold_state); |
87 | |
5406 | 88 endfunction |
9272
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
89 |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
90 %!demo |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
91 %! clf |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
92 %! A = rand (100); |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
93 %! [X, Y] = find (A > 0.9); |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
94 %! imshow (A) |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
95 %! hold on |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
96 %! plot (X, Y, 'o') |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
97 %! hold off |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
98 |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
99 %!demo |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
100 %! clf |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
101 %! hold on |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
102 %! imagesc(1./hilb(4)); |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
103 %! plot (1:4, "-s") |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
104 %! hold off |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
105 |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
106 %!demo |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
107 %! clf |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
108 %! hold on |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
109 %! imagesc(1./hilb(2)); |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
110 %! imagesc(1./hilb(4)); |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
111 %! hold off |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
112 |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
113 %!demo |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
114 %! clf |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
115 %! hold on |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
116 %! plot (1:4, "-s") |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
117 %! imagesc(1./hilb(4)); |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
118 %! hold off |
3eda945bda43
__go_draw_axes__.m: Fix rendering of overlaping images and line objects. Add demos as well.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
119 |