Mercurial > hg > octave-lyh
annotate scripts/plot/line.m @ 17014:4d9862d9fce5
line.m: avoid calling "gca ()" when a parent axes is specified as prop/val pair (bug #39483).
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Tue, 16 Jul 2013 20:41:20 +0200 |
parents | ddac88d32d6a |
children | 761d2be77e78 |
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}) |
6257 | 22 ## @deftypefnx {Function File} {} line (@var{x}, @var{y}, @var{z}) |
6895 | 23 ## @deftypefnx {Function File} {} line (@var{x}, @var{y}, @var{z}, @var{property}, @var{value}, @dots{}) |
6257 | 24 ## Create line object from @var{x} and @var{y} and insert in current |
6895 | 25 ## axes object. Return a handle (or vector of handles) to the line |
26 ## objects created. | |
27 ## | |
28 ## Multiple property-value pairs may be specified for the line, but they | |
29 ## must appear in pairs. | |
6257 | 30 ## @end deftypefn |
31 | |
32 ## Author: jwe | |
33 | |
34 function h = line (varargin) | |
35 | |
6405 | 36 ## make a default line object, and make it the current axes for |
37 ## the current figure. | |
17014
4d9862d9fce5
line.m: avoid calling "gca ()" when a parent axes is specified as prop/val pair (bug #39483).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16828
diff
changeset
|
38 [ax, varargin] = __plt_get_axis_arg__ ("line", varargin{:}); |
4d9862d9fce5
line.m: avoid calling "gca ()" when a parent axes is specified as prop/val pair (bug #39483).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16828
diff
changeset
|
39 if (isempty (ax)) |
4d9862d9fce5
line.m: avoid calling "gca ()" when a parent axes is specified as prop/val pair (bug #39483).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16828
diff
changeset
|
40 ax = gca (); |
4d9862d9fce5
line.m: avoid calling "gca ()" when a parent axes is specified as prop/val pair (bug #39483).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16828
diff
changeset
|
41 endif |
4d9862d9fce5
line.m: avoid calling "gca ()" when a parent axes is specified as prop/val pair (bug #39483).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16828
diff
changeset
|
42 |
4d9862d9fce5
line.m: avoid calling "gca ()" when a parent axes is specified as prop/val pair (bug #39483).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
16828
diff
changeset
|
43 tmp = __line__ (ax, varargin{:}); |
6257 | 44 |
6405 | 45 if (nargout > 0) |
46 h = tmp; | |
6257 | 47 endif |
48 | |
49 endfunction | |
13096 | 50 |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14849
diff
changeset
|
51 |
14535
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
52 %!demo |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
53 %! clf |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
54 %! x = 0:0.3:10; |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
55 %! y1 = cos (x); |
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
56 %! 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
|
57 %! 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
|
58 %! 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
|
59 %! 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
|
60 %! 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
|
61 %! 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
|
62 %! 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
|
63 %! 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
|
64 %! 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
|
65 %! xlim ([0 10]); |
14535
8150ccfffa22
Apply broadcasting to inputs of line().
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
66 |
13096 | 67 %!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
|
68 %! 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
|
69 %! unwind_protect |
13096 | 70 %! 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
|
71 %! assert (findobj (hf, "type", "line"), h); |
13096 | 72 %! assert (get (h, "xdata"), [0 1], eps); |
73 %! assert (get (h, "ydata"), [0 1], eps); | |
74 %! 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
|
75 %! 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
|
76 %! 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
|
77 %! assert (get (h, "linewidth"), get (0, "defaultlinelinewidth"), eps); |
13096 | 78 %! unwind_protect_cleanup |
79 %! close (hf); | |
80 %! end_unwind_protect | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
81 |