annotate scripts/plot/text.m @ 11416:74e285bb61c9

text.m: Add demo for text rotation and alignment.
author Ben Abbott <bpabbott@mac.com>
date Mon, 27 Dec 2010 11:13:06 -0500
parents 521f2bb7c443
children bc509d5f763f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2007 John W. Eaton
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 -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
20 ## @deftypefn {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{label})
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label})
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6419
diff changeset
22 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{label}, @var{p1}, @var{v1}, @dots{})
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6419
diff changeset
23 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label}, @var{p1}, @var{v1}, @dots{})
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
24 ## 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
25 ## @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
26 ## @var{label} may be used to specify the appearance of the text.
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
27 ## @end deftypefn
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
28
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
29 ## Author: jwe
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
30
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
31 function h = text (varargin)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
32
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
33 nargs = nargin;
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
34 offset = 0;
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
35
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
36 if (nargs > 2 && isnumeric (varargin{1}) && isnumeric (varargin{2}))
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
37 x = varargin{1};
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
38 y = varargin{2};
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
39 offset = 3;
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
40
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
41 if (nargin > 3 && isnumeric (varargin{3}))
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
42 z = varargin{3};
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
43 offset = 4;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
44 else
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
45 z = zeros (size (x));
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
46 offset = 3;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
47 endif
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
48
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
49 label = varargin{offset};
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
50 if (ischar (label) || iscellstr (label))
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
51 varargin(1:offset) = [];
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
52 if (ischar (label))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
53 label = cellstr (label);
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
54 endif
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
55 n = numel (label);
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
56 nx = numel (x);
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
57 ny = numel (y);
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
58 nz = numel (z);
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
59 else
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
60 error ("text: expecting label to be a character string or cell array of character strings");
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
61 endif
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
62 else
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
63 x = y = z = 0;
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
64 nx = ny = nz = 1;
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
65 label = {""};
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
66 n = 1;
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
67 endif
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
68
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
69 if (rem (numel (varargin), 2) == 0)
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
70
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
71 if (nx == ny && nx == nz)
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
72 pos = [x(:), y(:), z(:)];
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
73 ca = gca ();
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
74 tmp = zeros (n, 1);
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
75 if (n == 1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
76 label = label{1};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
77 for i = 1:nx
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
78 tmp(i) = __go_text__ (ca, "string", label,
11272
521f2bb7c443 text.m: Ensure text position property is set after units property.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
79 varargin{:},
521f2bb7c443 text.m: Ensure text position property is set after units property.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
80 "position", pos(i,:));
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
81 endfor
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
82 __request_drawnow__ ();
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
83 elseif (n == nx)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
84 for i = 1:nx
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
85 tmp(i) = __go_text__ (ca, "string", label{i},
11272
521f2bb7c443 text.m: Ensure text position property is set after units property.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
86 varargin{:},
521f2bb7c443 text.m: Ensure text position property is set after units property.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
87 "position", pos(i,:));
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
88 endfor
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
89 __request_drawnow__ ();
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
90 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7016
diff changeset
91 error ("text: dimension mismatch for coordinates and label");
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
92 endif
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
93 else
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
94 error ("text: dimension mismatch for coordinates");
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6257
diff changeset
95 endif
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
96
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
97 if (nargout > 0)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
98 h = tmp;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
99 endif
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
100
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
101 else
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
102 print_usage ();
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
103 endif
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
104
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
105 endfunction
11416
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
106
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
107 %!demo
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
108 %! clf
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
109 %! ha = {"left", "center", "right"};
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
110 %! va = {"bottom", "middle", "top"};
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
111 %! for t = 0:30:359;
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
112 %! for nh = 1:numel(ha)
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
113 %! x = [0.25 0.5 0.75](nh);
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
114 %! for nv = 1:numel(va)
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
115 %! y = [0.25 0.5 0.75](nv);
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
116 %! text (x, y, "Hello World",
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
117 %! "rotation", t,
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
118 %! "horizontalalignment", ha{nh},
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
119 %! "verticalalignment", va{nv})
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
120 %! endfor
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
121 %! endfor
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
122 %! endfor
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
123 %! set (gca, "xtick", [0.25, 0.5, 0.75],
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
124 %! "xticklabel", ha,
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
125 %! "ytick", [0.25, 0.5, 0.75],
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
126 %! "yticklabel", va)
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
127 %! axis ([0 1 0 1])
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
128 %! xlabel ("horizontal alignment")
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
129 %! ylabel ("vertical alignment")
74e285bb61c9 text.m: Add demo for text rotation and alignment.
Ben Abbott <bpabbott@mac.com>
parents: 11272
diff changeset
130 %! title ("text alignment and rotation (0:30:360 degrees)")