Mercurial > hg > octave-nkf
annotate scripts/plot/draw/line.m @ 20177:15e5eb7a0c1d
make dist: add updated zoom images to EXTRADIST (bug #44579)
* libgui/graphics/module.mk: add graphics/images/zoom-in.png, graphics/images/zoom-out.png, remove graphics/images/zoom.png
author | John Donoghue |
---|---|
date | Thu, 19 Mar 2015 08:37:47 -0400 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19075
diff
changeset
|
1 ## Copyright (C) 2005-2015 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}) |
17097
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{}) |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17097
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 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17097
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:
17097
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:
17097
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 (); |
19016
87c3848cf3c0
Fix bug when hggroup used with primitive graphic object (bug #42532).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
52 else |
87c3848cf3c0
Fix bug when hggroup used with primitive graphic object (bug #42532).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
53 hax = hax(1); |
17036
08dd9458684a
Overhaul __plt_get_axis_arg__ and newplot functions to avoid creating unnecessary axes.
Rik <rik@octave.org>
parents:
17015
diff
changeset
|
54 endif |
08dd9458684a
Overhaul __plt_get_axis_arg__ and newplot functions to avoid creating unnecessary axes.
Rik <rik@octave.org>
parents:
17015
diff
changeset
|
55 |
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
|
56 htmp = __line__ (hax, varargin{:}); |
6257 | 57 |
6405 | 58 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
|
59 h = htmp; |
6257 | 60 endif |
61 | |
62 endfunction | |
13096 | 63 |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14849
diff
changeset
|
64 |
14535
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
65 %!demo |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
66 %! clf |
19075
a8cacb2e98da
line.m: Add new %!demo of different linestyles.
Rik <rik@octave.org>
parents:
19016
diff
changeset
|
67 %! line ([0 1], [0.8 0.8], 'linestyle', '-', 'color', 'b'); |
a8cacb2e98da
line.m: Add new %!demo of different linestyles.
Rik <rik@octave.org>
parents:
19016
diff
changeset
|
68 %! line ([0 1], [0.6 0.6], 'linestyle', '--', 'color', 'g'); |
a8cacb2e98da
line.m: Add new %!demo of different linestyles.
Rik <rik@octave.org>
parents:
19016
diff
changeset
|
69 %! line ([0 1], [0.4 0.4], 'linestyle', ':', 'color', 'r'); |
a8cacb2e98da
line.m: Add new %!demo of different linestyles.
Rik <rik@octave.org>
parents:
19016
diff
changeset
|
70 %! line ([0 1], [0.2 0.2], 'linestyle', '-.', 'color', 'k'); |
a8cacb2e98da
line.m: Add new %!demo of different linestyles.
Rik <rik@octave.org>
parents:
19016
diff
changeset
|
71 %! ylim ([0 1]); |
a8cacb2e98da
line.m: Add new %!demo of different linestyles.
Rik <rik@octave.org>
parents:
19016
diff
changeset
|
72 %! title ('line() with various linestyles'); |
a8cacb2e98da
line.m: Add new %!demo of different linestyles.
Rik <rik@octave.org>
parents:
19016
diff
changeset
|
73 %! legend ('"-"', '"--"', '":"', '"-."', 'location', 'eastoutside'); |
a8cacb2e98da
line.m: Add new %!demo of different linestyles.
Rik <rik@octave.org>
parents:
19016
diff
changeset
|
74 |
a8cacb2e98da
line.m: Add new %!demo of different linestyles.
Rik <rik@octave.org>
parents:
19016
diff
changeset
|
75 %!demo |
a8cacb2e98da
line.m: Add new %!demo of different linestyles.
Rik <rik@octave.org>
parents:
19016
diff
changeset
|
76 %! clf |
14535
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
77 %! x = 0:0.3:10; |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
78 %! y1 = cos (x); |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
79 %! 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
|
80 %! 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
|
81 %! 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
|
82 %! 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
|
83 %! 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
|
84 %! 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
|
85 %! 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
|
86 %! 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
|
87 %! 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
|
88 %! xlim ([0 10]); |
14535
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
89 |
13096 | 90 %!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
|
91 %! 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
|
92 %! unwind_protect |
13096 | 93 %! 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
|
94 %! assert (findobj (hf, "type", "line"), h); |
13096 | 95 %! assert (get (h, "xdata"), [0 1], eps); |
96 %! assert (get (h, "ydata"), [0 1], eps); | |
97 %! 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
|
98 %! 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
|
99 %! 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
|
100 %! assert (get (h, "linewidth"), get (0, "defaultlinelinewidth"), eps); |
13096 | 101 %! unwind_protect_cleanup |
102 %! close (hf); | |
103 %! end_unwind_protect | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
104 |