Mercurial > octave-nkf
comparison scripts/plot/hold.m @ 12085:c5ab026894ef release-3-2-x
correctly toggle hold state
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 07 Sep 2009 08:01:41 +0200 |
parents | ad7a2f55c8b4 |
children | 95c3e38098bf |
comparison
equal
deleted
inserted
replaced
12084:bd994ce20158 | 12085:c5ab026894ef |
---|---|
44 ## @seealso{ishold, cla, newplot, clf} | 44 ## @seealso{ishold, cla, newplot, clf} |
45 ## @end deftypefn | 45 ## @end deftypefn |
46 | 46 |
47 function hold (varargin) | 47 function hold (varargin) |
48 | 48 |
49 if (nargin > 0 && numel (varargin{1}) == 1 && ishandle (varargin{1}(1)) | 49 if (nargin > 0 && numel (varargin{1}) == 1 && ishandle (varargin{1}) |
50 && strcmp (get (varargin{1}, "type"), "axes")) | 50 && strcmp (get (varargin{1}, "type"), "axes")) |
51 [h, varargin, nargs] = __plt_get_axis_arg__ ("hold", varargin{:}); | 51 [ax, varargin, nargs] = __plt_get_axis_arg__ ("hold", varargin{:}); |
52 elseif (nargin > 0 && numel (varargin{1}) > 1 && ishandle (varargin{1}(1))) | 52 elseif (nargin > 0 && numel (varargin{1}) > 1 && ishandle (varargin{1})) |
53 print_usage (); | 53 print_usage (); |
54 else | 54 else |
55 h = gcf (); | 55 ax = gca (); |
56 fig = gcf (); | |
56 nargs = numel (varargin); | 57 nargs = numel (varargin); |
57 endif | 58 endif |
58 | 59 |
59 hold_state = get (h, "nextplot"); | |
60 | |
61 if (nargs == 0) | 60 if (nargs == 0) |
62 if (strcmpi (hold_state, "add")) | 61 turn_hold_off = ishold (ax); |
63 hold_state = "replace"; | |
64 else | |
65 hold_state = "add"; | |
66 endif | |
67 elseif (nargs == 1) | 62 elseif (nargs == 1) |
68 state = varargin{1}; | 63 state = varargin{1}; |
69 if (ischar (state)) | 64 if (ischar (state)) |
70 if (strcmpi (state, "off")) | 65 if (strcmpi (state, "off")) |
71 hold_state = "replace"; | 66 turn_hold_off = true; |
72 elseif (strcmpi (state, "on")) | 67 elseif (strcmpi (state, "on")) |
73 hold_state = "add"; | 68 turn_hold_off = false; |
74 else | 69 else |
75 print_usage (); | 70 error ("hold: invalid hold state"); |
76 endif | 71 endif |
77 endif | 72 endif |
78 else | 73 else |
79 print_usage (); | 74 print_usage (); |
80 endif | 75 endif |
81 | 76 |
82 if (isfigure (h)) | 77 if (turn_hold_off) |
83 if (isempty (get (h, "currentaxes"))) | 78 set (ax, "nextplot", "replace"); |
84 set (h, "currentaxes", __go_axes__ (h)) | 79 else |
85 endif | 80 set (ax, "nextplot", "add"); |
86 axes_objs = findobj (h, "type", "axes"); | 81 set (fig, "nextplot", "add"); |
87 h = [h; axes_objs]; | |
88 endif | 82 endif |
89 | |
90 set (h, "nextplot", hold_state); | |
91 | 83 |
92 endfunction | 84 endfunction |
93 | 85 |
94 %!demo | 86 %!demo |
95 %! clf | 87 %! clf |