annotate scripts/plot/text.m @ 14249:27abe77158d6

Changes to allow plot demos to be converted and run by Matlab. * text.m, waitbar.m
author Ben Abbott <bpabbott@mac.com>
date Sun, 22 Jan 2012 13:47:15 -0500
parents 4506eade9f04
children 5d3a684236b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14001
diff changeset
1 ## Copyright (C) 2007-2012 John W. Eaton
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
2 ##
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
4 ##
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
8 ## your option) any later version.
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
9 ##
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
14 ##
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
18
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
20 ## @deftypefn {Function File} {} text (@var{x}, @var{y}, @var{label})
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
21 ## @deftypefnx {Function File} {} text (@var{x}, @var{y}, @var{z}, @var{label})
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
22 ## @deftypefnx {Function File} {} text (@var{x}, @var{y}, @var{label}, @var{p1}, @var{v1}, @dots{})
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
23 ## @deftypefnx {Function File} {} text (@var{x}, @var{y}, @var{z}, @var{label}, @var{p1}, @var{v1}, @dots{})
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
24 ## @deftypefnx {Function File} {@var{h} =} text (@dots{})
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
25 ## Create a text object with text @var{label} at position @var{x},
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6419
diff changeset
26 ## @var{y}, @var{z} on the current axes. Property-value pairs following
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6419
diff changeset
27 ## @var{label} may be used to specify the appearance of the text.
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
28 ##
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
29 ## The optional return value @var{h} is a graphics handle to the created text
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
30 ## object.
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
31 ## @end deftypefn
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
32
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
33 ## Author: jwe
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
34
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
35 function h = text (varargin)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
36
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
37 nargs = nargin;
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
38 offset = 0;
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
39
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
40 if (nargs > 2 && isnumeric (varargin{1}) && isnumeric (varargin{2}))
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
41 x = varargin{1};
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
42 y = varargin{2};
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
43 offset = 3;
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
44
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
45 if (nargin > 3 && isnumeric (varargin{3}))
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
46 z = varargin{3};
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
47 offset = 4;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
48 else
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
49 z = zeros (size (x));
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
50 offset = 3;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
51 endif
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
52
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
53 label = varargin{offset};
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
54 varargin(1:offset) = [];
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
55
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
56 nx = numel (x);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
57 ny = numel (y);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
58 nz = numel (z);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
59 if (ischar (label) || isnumeric (label))
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
60 nt = size (label, 1);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
61 if (nx > 1 && nt == 1)
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
62 ## Mutiple text objects with same string
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
63 label = repmat ({label}, [nx, 1]);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
64 nt = nx;
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
65 elseif (nx > 1 && nt == nx)
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
66 ## Mutiple text objects with different strings
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
67 label = cellstr (label);
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
68 elseif (ischar (label))
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
69 ## Single text object with one or more lines
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
70 label = {label};
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
71 endif
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
72 elseif (iscell (label))
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
73 nt = numel (label);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
74 if (nx > 1 && nt == 1)
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
75 label = repmat ({label}, [nx, 1]);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
76 nt = nx;
12971
e65d1488ff6a text.m: Improve logic and error checking. Modify demo.
Ben Abbott <bpabbott@mac.com>
parents: 12965
diff changeset
77 elseif (! (nx > 1 && nt == nx))
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
78 label = {label};
12971
e65d1488ff6a text.m: Improve logic and error checking. Modify demo.
Ben Abbott <bpabbott@mac.com>
parents: 12965
diff changeset
79 nt = 1;
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
80 endif
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
81 else
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11424
diff changeset
82 error ("text: expecting LABEL to be a character string or cell array of character strings");
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
83 endif
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
84 else
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
85 x = y = z = 0;
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
86 nx = ny = nz = 1;
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
87 label = {""};
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
88 nt = 1;
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
89 endif
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
90
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
91 if (rem (numel (varargin), 2) == 0)
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
92
12971
e65d1488ff6a text.m: Improve logic and error checking. Modify demo.
Ben Abbott <bpabbott@mac.com>
parents: 12965
diff changeset
93 if (nx == ny && nx == nz && (nt == nx || nt == 1 || nx == 1))
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
94 pos = [x(:), y(:), z(:)];
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
95 ca = gca ();
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
96 tmp = zeros (nt, 1);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
97 if (nx == 1)
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
98 ## TODO - Modify __go_text__() to accept cell-strings
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
99 tmp = __go_text__ (ca, "string", "foobar",
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
100 varargin{:},
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
101 "position", pos);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
102 set (tmp, "string", label{1});
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
103 elseif (nt == nx)
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
104 for n = 1:nt
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
105 tmp(n) = __go_text__ (ca, "string", label{n},
11272
521f2bb7c443 text.m: Ensure text position property is set after units property.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
106 varargin{:},
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
107 "position", pos(n,:));
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
108 endfor
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
109 __request_drawnow__ ();
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
110 else
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11424
diff changeset
111 error ("text: dimension mismatch for coordinates and LABEL");
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
112 endif
12971
e65d1488ff6a text.m: Improve logic and error checking. Modify demo.
Ben Abbott <bpabbott@mac.com>
parents: 12965
diff changeset
113 elseif (nt == nx || nt == 1 || nx == 1)
e65d1488ff6a text.m: Improve logic and error checking. Modify demo.
Ben Abbott <bpabbott@mac.com>
parents: 12965
diff changeset
114 error ("text: dimension mismatch for coordinates");
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
115 else
12971
e65d1488ff6a text.m: Improve logic and error checking. Modify demo.
Ben Abbott <bpabbott@mac.com>
parents: 12965
diff changeset
116 error ("text: mismatch betwween coordinates and strings");
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
117 endif
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
118
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
119 if (nargout > 0)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
120 h = tmp;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
121 endif
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
122
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
123 else
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
124 print_usage ();
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
125 endif
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
126
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
127 endfunction
11416
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
128
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
129
11416
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
130 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
131 %! clf;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
132 %! ha = {'left', 'center', 'right'};
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
133 %! va = {'bottom', 'middle', 'top'};
14249
27abe77158d6 Changes to allow plot demos to be converted and run by Matlab.
Ben Abbott <bpabbott@mac.com>
parents: 14245
diff changeset
134 %! x = [0.25 0.5 0.75];
27abe77158d6 Changes to allow plot demos to be converted and run by Matlab.
Ben Abbott <bpabbott@mac.com>
parents: 14245
diff changeset
135 %! y = x;
11416
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
136 %! for t = 0:30:359;
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
137 %! for nh = 1:numel(ha)
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
138 %! for nv = 1:numel(va)
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
139 %! text (x(nh), y(nv), 'Hello World', ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
140 %! 'rotation', t, ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
141 %! 'horizontalalignment', ha{nh}, ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
142 %! 'verticalalignment', va{nv});
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
143 %! end
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
144 %! end
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
145 %! end
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
146 %! set (gca, 'xtick', [0.25, 0.5, 0.75], ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
147 %! 'xticklabel', ha, ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
148 %! 'ytick', [0.25, 0.5, 0.75], ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
149 %! 'yticklabel', va);
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
150 %! axis ([0 1 0 1]);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
151 %! xlabel ('horizontal alignment');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
152 %! ylabel ('vertical alignment');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
153 %! title ('text alignment and rotation (0:30:360 degrees)');
11424
bc509d5f763f text.m: New demo for 3D plot and text with verticalalignment.
Ben Abbott <bpabbott@mac.com>
parents: 11416
diff changeset
154
bc509d5f763f text.m: New demo for 3D plot and text with verticalalignment.
Ben Abbott <bpabbott@mac.com>
parents: 11416
diff changeset
155 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
156 %! clf;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
157 %! h = mesh (peaks, 'edgecolor', 0.7 * [1 1 1], ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
158 %! 'facecolor', 'none', ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
159 %! 'facealpha', 0);
11424
bc509d5f763f text.m: New demo for 3D plot and text with verticalalignment.
Ben Abbott <bpabbott@mac.com>
parents: 11416
diff changeset
160 %! for t = 0:45:359;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
161 %! text (25, 25, 0, 'Vertical Alignment = Bottom', ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
162 %! 'rotation', t, ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
163 %! 'horizontalalignment', 'left', ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
164 %! 'verticalalignment', 'bottom');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
165 %! end
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
166 %! caxis ([-100 100]);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
167 %! title ('Vertically Aligned at Bottom');
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
168
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
169 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
170 %! clf;
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
171 %! axis ([0 8 0 8]);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
172 %! title (['1st title';'2nd title']);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
173 %! xlabel (['1st xlabel';'2nd xlabel']);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
174 %! ylabel (['1st ylabel';'2nd ylabel']);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
175 %! text (4, 4, {'Hello', 'World'}, ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
176 %! 'horizontalalignment', 'center', ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
177 %! 'verticalalignment', 'middle');
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
178 %! grid on;
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
179
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
180 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
181 %! clf;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
182 %! h = mesh (peaks (), 'edgecolor', 0.7 * [1 1 1], ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
183 %! 'facecolor', 'none', ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
184 %! 'facealpha', 0);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
185 %! title (['1st title';'2nd title']);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
186 %! xlabel (['1st xlabel';'2nd xlabel']);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
187 %! ylabel (['1st ylabel';'2nd ylabel']);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
188 %! zlabel (['1st zlabel';'2nd zlabel']);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
189 %! text (0, 0, 5, {'Hello', 'World'}, ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
190 %! 'horizontalalignment', 'center', ...
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
191 %! 'verticalalignment', 'middle');
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
192 %! hold on;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
193 %! plot3 (0, 0, 5, '+k');
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
194
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
195 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
196 %! clf;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
197 %! h = text (0.5, 0.3, 'char');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
198 %! assert ('char', class (get (h, 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
199 %! h = text (0.5, 0.4, ['char row 1'; 'char row 2']);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
200 %! assert ('char', class (get (h, 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
201 %! h = text (0.5, 0.6, {'cell2str (1,1)', 'cell2str (1,2)'; 'cell2str (2,1)', 'cell2str (2,2)'});
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
202 %! assert ('cell', class (get (h, 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
203 %! h = text (0.5, 0.8, 'foobar');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
204 %! set (h, 'string', 1:3);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
205 %! h = text ([0.1, 0.1], [0.3, 0.4], 'one string & two objects');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
206 %! assert ('char', class (get (h(1), 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
207 %! assert ('char', class (get (h(2), 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
208 %! h = text ([0.1, 0.1], [0.5, 0.6], {'one cellstr & two objects'});
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
209 %! assert ('cell', class (get (h(1), 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
210 %! assert ('cell', class (get (h(2), 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
211 %! h = text ([0.1, 0.1], [0.7, 0.8], {'cellstr 1 object 1', 'cellstr 2 object 2'});
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
212 %! assert ('char', class (get (h(1), 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
213 %! assert ('char', class (get (h(2), 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
214 %! h = text ([0.1, 0.1], [0.1, 0.2], ['1st string & 1st object'; '2nd string & 2nd object']);
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
215 %! assert ('char', class (get (h(1), 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
216 %! assert ('char', class (get (h(2), 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
217 %! h = text (0.7, 0.6, 'single string');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
218 %! assert ('char', class (get (h, 'string')));
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
219 %! h = text (0.7, 0.5, {'single cell-string'});
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
220 %! assert ('cell', class (get (h, 'string')));
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
221 %! xlabel (1:2);
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
222 %! ylabel (1:2);
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
223 %! title (1:2);
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12437
diff changeset
224
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
225 %!test
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
226 %! hf = figure ("visible", "off");
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13137
diff changeset
227 %! unwind_protect
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
228 %! h = text (0.5, 0.3, "char");
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
229 %! assert ("char", class (get (h, "string")));
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
230 %! h = text (0.5, 0.4, ["char row 1"; "char row 2"]);
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
231 %! assert ("char", class (get (h, "string")));
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
232 %! h = text (0.5, 0.6, {"cell2str (1,1)", "cell2str (1,2)"; "cell2str (2,1)", "cell2str (2,2)"});
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
233 %! assert ("cell", class (get (h, "string")));
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
234 %! h = text (0.5, 0.8, "foobar");
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
235 %! set (h, "string", 1:3);
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
236 %! h = text ([0.1, 0.1], [0.3, 0.4], "one string & two objects");
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
237 %! assert ("char", class (get (h(1), "string")));
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
238 %! assert ("char", class (get (h(2), "string")));
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
239 %! h = text ([0.1, 0.1], [0.5, 0.6], {"one cellstr & two objects"});
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
240 %! assert ("cell", class (get (h(1), "string")));
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
241 %! assert ("cell", class (get (h(2), "string")));
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
242 %! h = text ([0.1, 0.1], [0.7, 0.8], {"cellstr 1 object 1", "cellstr 2 object 2"});
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
243 %! assert ("char", class (get (h(1), "string")));
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
244 %! assert ("char", class (get (h(2), "string")));
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
245 %! h = text ([0.1, 0.1], [0.1, 0.2], ["1st string & 1st object"; "2nd string & 2nd object"]);
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
246 %! assert ("char", class (get (h(1), "string")));
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
247 %! assert ("char", class (get (h(2), "string")));
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
248 %! h = text (0.7, 0.6, "single string");
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
249 %! assert ("char", class (get (h, "string")));
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
250 %! h = text (0.7, 0.5, {"single cell-string"});
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
251 %! assert ("cell", class (get (h, "string")));
13136
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
252 %! unwind_protect_cleanup
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
253 %! close (hf);
79b9a7669bb8 Tests added for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12971
diff changeset
254 %! end_unwind_protect
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
255