annotate scripts/plot/legend.m @ 6272:a1f3d3b7ee5c

[project @ 2007-02-06 02:09:48 by jwe]
author jwe
date Tue, 06 Feb 2007 02:09:48 +0000
parents 44c91c5dfe1d
children a8dd70bacc1e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2001 Laurent Mazet
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
2 ## Copyright (C) 2006 John W. Eaton
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
3 ##
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
4 ## This program is free software; it is distributed in the hope that it
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
5 ## will be useful, but WITHOUT ANY WARRANTY; without even the implied
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
6 ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
7 ## the GNU General Public License for more details.
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
8 ##
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
9 ## You should have received a copy of the GNU General Public License
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
10 ## along with this file; see the file COPYING. If not, write to the
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
11 ## Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
12 ## 02111-1307, USA.
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
13
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
14 ## -*- texinfo -*-
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
15 ## @deftypefn {Function File} {} legend (@var{st1}, @var{st2}, @var{st3}, @var{...})
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
16 ## @deftypefnx {Function File} {} legend (@var{st1}, @var{st2}, @var{st3}, @var{...}, @var{pos})
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
17 ## @deftypefnx {Function File} {} legend (@var{matstr})
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
18 ## @deftypefnx {Function File} {} legend (@var{matstr}, @var{pos})
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
19 ## @deftypefnx {Function File} {} legend (@var{cell})
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
20 ## @deftypefnx {Function File} {} legend (@var{cell}, @var{pos})
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefnx {Function File} {} legend ('@var{func}')
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
22 ##
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
23 ## Legend puts a legend on the current plot using the specified strings
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
24 ## as labels. Use independant strings (@var{st1}, @var{st2}, @var{st3}...), a
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
25 ## matrix of strings (@var{matstr}), or a cell array of strings (@var{cell}) to
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
26 ## specify legends. Legend works on line graphs, bar graphs, etc...
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
27 ## Be sure to call plot before calling legend.
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
28 ##
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
29 ## @var{pos} optionally places the legend in the specified location:
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
30 ##
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
31 ## @multitable @columnfractions 0.1 0.1 0.8
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
32 ## @item @tab 0 @tab
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
33 ## Don't move the legend box (default)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
34 ## @item @tab 1 @tab
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
35 ## Upper right-hand corner
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
36 ## @item @tab 2 @tab
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
37 ## Upper left-hand corner
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
38 ## @item @tab 3 @tab
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
39 ## Lower left-hand corner
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
40 ## @item @tab 4 @tab
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
41 ## Lower right-hand corner
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
42 ## @item @tab -1 @tab
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
43 ## To the top right of the plot
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
44 ## @item @tab -2 @tab
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
45 ## To the bottom right of the plot
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
46 ## @item @tab -3 @tab
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
47 ## To the bottom of the plot
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
48 ## @item @tab [@var{x}, @var{y}] @tab
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
49 ## To the arbitrary postion in plot [@var{x}, @var{y}]
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
50 ## @end multitable
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
51 ##
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
52 ## Some specific functions are directely avaliable using @var{func}:
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
53 ##
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
54 ## @table @code
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
55 ## @item show
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
56 ## Show legends from the plot
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
57 ## @item hide
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
58 ## @itemx off
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
59 ## Hide legends from the plot
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
60 ## @item boxon
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
61 ## Draw a box around legends
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
62 ## @item boxoff
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
63 ## Withdraw the box around legends
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
64 ## @item left
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
65 ## Text is to the left of the keys
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
66 ## @item right
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
67 ## Text is to the right of the keys
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
68 ## @end table
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
69 ## @end deftypefn
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
70
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
71 ## PKG_ADD mark_as_command legend
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
72
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
73 function legend (varargin)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
74
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
75 nargs = nargin;
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
76
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
77 ca = gca ();
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
78
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
79 if (nargs > 0)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
80 pos = varargin{nargs};
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
81 if (isnumeric (pos) && isscalar (pos) && round (pos) == pos)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
82 if (pos >= -3 && pos <= 4)
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
83 set (ca, "keypos", pos);
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
84 nargs--;
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
85 else
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
86 error ("legend: invalid position specified");
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
87 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
88 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
89 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
90
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
91 kids = get (ca, "children");
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
92 nkids = numel (kids);
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
93 k = 1;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
94 turn_on_legend = false;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
95
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
96 if (nargs == 1)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
97 arg = varargin{1};
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
98 if (ischar (arg))
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
99 if (rows (arg) == 1)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
100 str = tolower (deblank (arg));
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
101 switch (str)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
102 case {"off", "hide"}
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
103 set (ca, "key", "off");
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
104 case "show"
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
105 set (ca, "key", "on");
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
106 case "toggle"
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
107 val = get (ca, "key");
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
108 if (strcmp (val, "on"))
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
109 set (ca, "key", "off");
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
110 else
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
111 set (ca, "key", "on");
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
112 endif
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
113 case "boxon"
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
114 set (ca, "key", "on", "keybox", "on");
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
115 case "boxoff"
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
116 set (ca, "keybox", "off");
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
117 otherwise
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
118 while (k <= nkids && ! strcmp (get (kids(k), "type"), "line"))
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
119 k++;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
120 endwhile
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
121 if (k <= nkids)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
122 turn_on_legend = true;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
123 set (kids(k), "keylabel", arg);
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
124 else
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
125 warning ("legend: ignoring extra labels");
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
126 endif
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
127 endswitch
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
128 nargs--;
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
129 else
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
130 varargin = cellstr (arg);
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
131 nargs = numel (vargin);
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
132 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
133 elseif (iscellstr (arg))
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
134 varargin = arg;
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
135 nargs = numel (varargin);
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
136 else
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
137 error ("legend: expecting argument to be a character string");
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
138 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
139 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
140
6272
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
141 if (nargs > 0)
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
142 have_data = false;
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
143 for i = 1:nkids
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
144 if (strcmp (get (kids(k), "type"), "line"))
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
145 have_data = true;
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
146 break;
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
147 endif
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
148 endfor
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
149 if (! have_data)
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
150 warning ("legend: plot data is empty; setting key labels has no effect");
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
151 endif
6147
e14b0e9b7bf7 [project @ 2006-11-09 03:28:01 by jwe]
jwe
parents: 6146
diff changeset
152 endif
e14b0e9b7bf7 [project @ 2006-11-09 03:28:01 by jwe]
jwe
parents: 6146
diff changeset
153
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
154 for i = 1:nargs
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
155 arg = varargin{i};
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
156 if (ischar (arg))
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
157 while (k <= nkids && ! strcmp (get (kids(k), "type"), "line"))
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
158 k++;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
159 endwhile
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
160 if (k <= nkids)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
161 set (kids(k), "keylabel", arg);
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
162 turn_on_legend = true;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
163 elseif (! warned)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
164 warned = true;
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
165 warning ("legend: ignoring extra labels");
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
166 endif
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
167 else
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
168 error ("legend: expecting argument to be a character string");
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
169 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
170 endfor
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
171
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
172 if (turn_on_legend)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
173 set (ca, "key", "on");
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
174 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
175
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
176 endfunction
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
177
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
178 %!demo
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
179 %! close all;
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
180 %! plot(1:10, 1:10);
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
181 %! title("a very long label can sometimes cause problems");
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
182 %! legend({"hello world"}, -1)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
183
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
184 %!demo
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
185 %! close all;
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
186 %! labels = {};
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
187 %! for i = 1:5
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
188 %! plot(1:100, i + rand(100,1)); hold on;
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
189 %! labels = {labels{:}, strcat("Signal ", num2str(i))};
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
190 %! endfor; hold off;
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
191 %! title("Signals with random offset and uniform noise")
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
192 %! xlabel("Sample Nr [k]"); ylabel("Amplitude [V]");
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
193 %! legend(labels, -1)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
194 %! legend("boxon")