Mercurial > hg > octave-nkf
comparison scripts/plot/newplot.m @ 16076:c90c9623b20f
newplot.m: Return handle to created axes for Matlab compatibility (Bug #38146)
* newplot.m: Return handle to created axes if nargout > 0.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 20 Feb 2013 16:11:47 -0800 |
parents | f3d52523cde1 |
children | 08dd9458684a |
comparison
equal
deleted
inserted
replaced
16075:7cfb186592de | 16076:c90c9623b20f |
---|---|
15 ## You should have received a copy of the GNU General Public License | 15 ## You should have received a copy of the GNU General Public License |
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} newplot () | 20 ## @deftypefn {Function File} {} newplot () |
21 ## @deftypefnx {Function File} {@var{h} =} newplot () | |
21 ## Prepare graphics engine to produce a new plot. This function is | 22 ## Prepare graphics engine to produce a new plot. This function is |
22 ## called at the beginning of all high-level plotting functions. | 23 ## called at the beginning of all high-level plotting functions. |
23 ## It is not normally required in user programs. | 24 ## It is not normally required in user programs. |
25 ## | |
26 ## The optional return value @var{h} is a graphics handle to the created | |
27 ## axes (not figure). | |
24 ## @end deftypefn | 28 ## @end deftypefn |
25 | 29 |
26 function newplot () | 30 function h = newplot () |
27 | 31 |
28 if (nargin == 0) | 32 if (nargin == 0) |
29 cf = gcf (); | 33 cf = gcf (); |
30 fnp = get (cf, "nextplot"); | 34 fnp = get (cf, "nextplot"); |
31 switch (fnp) | 35 switch (fnp) |
57 __go_axes_init__ (ca, "replace"); | 61 __go_axes_init__ (ca, "replace"); |
58 __request_drawnow__ (); | 62 __request_drawnow__ (); |
59 otherwise | 63 otherwise |
60 error ("newplot: unrecognized nextplot property for current axes"); | 64 error ("newplot: unrecognized nextplot property for current axes"); |
61 endswitch | 65 endswitch |
66 if (nargout > 0) | |
67 h = ca; | |
68 endif | |
62 else | 69 else |
63 print_usage (); | 70 print_usage (); |
64 endif | 71 endif |
65 | 72 |
66 endfunction | 73 endfunction |
68 | 75 |
69 %!test | 76 %!test |
70 %! hf = figure ("visible", "off"); | 77 %! hf = figure ("visible", "off"); |
71 %! unwind_protect | 78 %! unwind_protect |
72 %! p = plot ([0, 1]); | 79 %! p = plot ([0, 1]); |
73 %! newplot; | 80 %! ha = newplot (); |
81 %! assert (ha, gca); | |
74 %! assert (isempty (get (gca, "children"))); | 82 %! assert (isempty (get (gca, "children"))); |
75 %! unwind_protect_cleanup | 83 %! unwind_protect_cleanup |
76 %! close (hf); | 84 %! close (hf); |
77 %! end_unwind_protect | 85 %! end_unwind_protect |
78 | 86 |