Mercurial > hg > octave-lyh
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 |
rev | line source |
---|---|
6257 | 1 ## Copyright (C) 2007 John W. Eaton |
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:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{label}) |
6257 | 21 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label}) |
6895 | 22 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{label}, @var{p1}, @var{v1}, @dots{}) |
23 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label}, @var{p1}, @var{v1}, @dots{}) | |
6257 | 24 ## Create a text object with text @var{label} at position @var{x}, |
6895 | 25 ## @var{y}, @var{z} on the current axes. Property-value pairs following |
26 ## @var{label} may be used to specify the appearance of the text. | |
6257 | 27 ## @end deftypefn |
28 | |
29 ## Author: jwe | |
30 | |
31 function h = text (varargin) | |
32 | |
6405 | 33 nargs = nargin; |
34 offset = 0; | |
35 | |
36 if (nargs > 2 && isnumeric (varargin{1}) && isnumeric (varargin{2})) | |
37 x = varargin{1}; | |
38 y = varargin{2}; | |
39 offset = 3; | |
6257 | 40 |
41 if (nargin > 3 && isnumeric (varargin{3})) | |
42 z = varargin{3}; | |
43 offset = 4; | |
44 else | |
45 z = zeros (size (x)); | |
46 offset = 3; | |
47 endif | |
48 | |
49 label = varargin{offset}; | |
50 if (ischar (label) || iscellstr (label)) | |
51 varargin(1:offset) = []; | |
52 if (ischar (label)) | |
10549 | 53 label = cellstr (label); |
6257 | 54 endif |
55 n = numel (label); | |
56 nx = numel (x); | |
57 ny = numel (y); | |
58 nz = numel (z); | |
59 else | |
60 error ("text: expecting label to be a character string or cell array of character strings"); | |
61 endif | |
6405 | 62 else |
63 x = y = z = 0; | |
64 nx = ny = nz = 1; | |
65 label = {""}; | |
66 n = 1; | |
67 endif | |
6257 | 68 |
6405 | 69 if (rem (numel (varargin), 2) == 0) |
70 | |
71 if (nx == ny && nx == nz) | |
72 pos = [x(:), y(:), z(:)]; | |
73 ca = gca (); | |
74 tmp = zeros (n, 1); | |
75 if (n == 1) | |
10549 | 76 label = label{1}; |
77 for i = 1:nx | |
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 | 81 endfor |
82 __request_drawnow__ (); | |
6405 | 83 elseif (n == nx) |
10549 | 84 for i = 1:nx |
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 | 88 endfor |
89 __request_drawnow__ (); | |
6405 | 90 else |
10549 | 91 error ("text: dimension mismatch for coordinates and label"); |
6405 | 92 endif |
93 else | |
94 error ("text: dimension mismatch for coordinates"); | |
95 endif | |
6257 | 96 |
97 if (nargout > 0) | |
98 h = tmp; | |
99 endif | |
100 | |
101 else | |
102 print_usage (); | |
103 endif | |
104 | |
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)") |