Mercurial > hg > octave-lyh
annotate scripts/plot/line.m @ 17455:359366a4994f
waitbar.m: Use Octave coding conventions.
* scripts/plot/waitbar.m: Rename 'retval' to 'h' to match documentation.
Use 'hf', 'hp' for figure and patch graphics handles.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 19 Sep 2013 14:26:47 -0700 |
parents | eaab03308c0b |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
1 ## Copyright (C) 2005-2012 John W. Eaton |
6257 | 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. | |
6257 | 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/>. | |
6257 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
20 ## @deftypefn {Function File} {} line () |
6405 | 21 ## @deftypefnx {Function File} {} line (@var{x}, @var{y}) |
17101
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
17036
diff
changeset
|
22 ## @deftypefnx {Function File} {} line (@var{x}, @var{y}, @var{property}, @var{value}, @dots{}) |
6257 | 23 ## @deftypefnx {Function File} {} line (@var{x}, @var{y}, @var{z}) |
6895 | 24 ## @deftypefnx {Function File} {} line (@var{x}, @var{y}, @var{z}, @var{property}, @var{value}, @dots{}) |
17015
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
25 ## @deftypefnx {Function File} {} line (@var{property}, @var{value}, @dots{}) |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17101
diff
changeset
|
26 ## @deftypefnx {Function File} {} line (@var{hax}, @dots{}) |
17015
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
27 ## @deftypefnx {Function File} {@var{h} =} line (@dots{}) |
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
28 ## Create line object from @var{x} and @var{y} (and possibly @var{z}) and |
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
29 ## insert in the current axes. |
6895 | 30 ## |
17015
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
31 ## Multiple property-value pairs may be specified for the line object, but they |
6895 | 32 ## must appear in pairs. |
17015
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
33 ## |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17101
diff
changeset
|
34 ## If the first argument @var{hax} is an axes handle, then plot into this axis, |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17101
diff
changeset
|
35 ## rather than the current axes returned by @code{gca}. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17101
diff
changeset
|
36 ## |
17015
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
37 ## The optional return value @var{h} is a graphics handle (or vector of handles) |
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
38 ## to the line objects created. |
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
39 ## |
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
40 ## @seealso{image, patch, rectangle, surface, text} |
6257 | 41 ## @end deftypefn |
42 | |
43 ## Author: jwe | |
44 | |
45 function h = line (varargin) | |
46 | |
17036
08dd9458684a
Overhaul __plt_get_axis_arg__ and newplot functions to avoid creating unnecessary axes.
Rik <rik@octave.org>
parents:
17015
diff
changeset
|
47 ## Get axis argument which may be in a 'parent' PROP/VAL pair |
17015
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
48 [hax, varargin] = __plt_get_axis_arg__ ("line", varargin{:}); |
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
49 |
17036
08dd9458684a
Overhaul __plt_get_axis_arg__ and newplot functions to avoid creating unnecessary axes.
Rik <rik@octave.org>
parents:
17015
diff
changeset
|
50 if (isempty (hax)) |
08dd9458684a
Overhaul __plt_get_axis_arg__ and newplot functions to avoid creating unnecessary axes.
Rik <rik@octave.org>
parents:
17015
diff
changeset
|
51 hax = gca (); |
08dd9458684a
Overhaul __plt_get_axis_arg__ and newplot functions to avoid creating unnecessary axes.
Rik <rik@octave.org>
parents:
17015
diff
changeset
|
52 endif |
08dd9458684a
Overhaul __plt_get_axis_arg__ and newplot functions to avoid creating unnecessary axes.
Rik <rik@octave.org>
parents:
17015
diff
changeset
|
53 |
17015
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
54 htmp = __line__ (hax, varargin{:}); |
6257 | 55 |
6405 | 56 if (nargout > 0) |
17015
761d2be77e78
__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs.
Rik <rik@octave.org>
parents:
17014
diff
changeset
|
57 h = htmp; |
6257 | 58 endif |
59 | |
60 endfunction | |
13096 | 61 |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14849
diff
changeset
|
62 |
14535
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
63 %!demo |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
64 %! clf |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
65 %! x = 0:0.3:10; |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
66 %! y1 = cos (x); |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
67 %! y2 = sin (x); |
14849
f6d3d5b0bd42
test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents:
14535
diff
changeset
|
68 %! subplot (3,1,1); |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14849
diff
changeset
|
69 %! args = {'color', 'b', 'marker', 's'}; |
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14849
diff
changeset
|
70 %! line ([x(:), x(:)], [y1(:), y2(:)], args{:}); |
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14849
diff
changeset
|
71 %! title ('Test broadcasting for line()'); |
14849
f6d3d5b0bd42
test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents:
14535
diff
changeset
|
72 %! subplot (3,1,2); |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14849
diff
changeset
|
73 %! line (x(:), [y1(:), y2(:)], args{:}); |
14849
f6d3d5b0bd42
test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents:
14535
diff
changeset
|
74 %! subplot (3,1,3); |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14849
diff
changeset
|
75 %! line ([x(:), x(:)+pi/2], y1(:), args{:}); |
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14849
diff
changeset
|
76 %! xlim ([0 10]); |
14535
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
77 |
13096 | 78 %!test |
13124
2ea1658ad049
Don't use explicit figure number for tests to avoid interference with any figures opened by user.
Kai Habel <kai.habel@gmx.de>
parents:
13115
diff
changeset
|
79 %! hf = figure ("visible", "off"); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
13124
diff
changeset
|
80 %! unwind_protect |
13096 | 81 %! h = line; |
13115
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
13111
diff
changeset
|
82 %! assert (findobj (hf, "type", "line"), h); |
13096 | 83 %! assert (get (h, "xdata"), [0 1], eps); |
84 %! assert (get (h, "ydata"), [0 1], eps); | |
85 %! assert (get (h, "type"), "line"); | |
13115
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
13111
diff
changeset
|
86 %! assert (get (h, "color"), get (0, "defaultlinecolor")); |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
13111
diff
changeset
|
87 %! assert (get (h, "linestyle"), get (0, "defaultlinelinestyle")); |
cd808de114c1
Allow surface and patch to be called w/o arguments. Adding and fixing tests.
Kai Habel <kai.habel@gmx.de>
parents:
13111
diff
changeset
|
88 %! assert (get (h, "linewidth"), get (0, "defaultlinelinewidth"), eps); |
13096 | 89 %! unwind_protect_cleanup |
90 %! close (hf); | |
91 %! end_unwind_protect | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
92 |