1 ## Copyright (C) 2008-2012 David Bateman
3 ## This file is part of Octave.
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} clabel (@var{c}, @var{h})
21 ## @deftypefnx {Function File} {} clabel (@var{c}, @var{h}, @var{v})
22 ## @deftypefnx {Function File} {} clabel (@var{c}, @var{h}, "manual")
23 ## @deftypefnx {Function File} {} clabel (@var{c})
24 ## @deftypefnx {Function File} {} clabel (@var{c}, @var{h})
25 ## @deftypefnx {Function File} {} clabel (@dots{}, @var{prop}, @var{val}, @dots{})
26 ## @deftypefnx {Function File} {@var{h} =} clabel (@dots{})
27 ## Add labels to the contours of a contour plot. The contour plot is specified
28 ## by the contour matrix @var{c} and optionally the contourgroup object @var{h}
29 ## that are returned by @code{contour}, @code{contourf} and @code{contour3}.
30 ## The contour labels are rotated and placed in the contour itself.
32 ## By default, all contours are labeled. However, the contours to label can be
33 ## specified by the vector @var{v}. If the "manual" argument is given then
34 ## the contours to label can be selected with the mouse.
36 ## Additional property/value pairs that are valid properties of text objects
37 ## can be given and are passed to the underlying text objects. Additionally,
38 ## the property "LabelSpacing" is available allowing the spacing between labels
39 ## on a contour (in points) to be specified. The default is 144 points, or 2
42 ## The optional return value @var{h} is a vector of graphics handles to
43 ## the text objects representing each label.
44 ## The "userdata" property of the text objects contains the numerical value of
47 ## An example of the use of @code{clabel} is
51 ## [c, h] = contour (peaks (), -4 : 6);
52 ## clabel (c, h, -4:2:6, "fontsize", 12);
56 ## @seealso{contour, contourf, contour3, meshc, surfc, text}
59 function retval = clabel (c, varargin)
60 label_spacing = 2 * 72;
62 have_labelspacing = false;
70 if (isscalar (arg) && ishandle(arg)
71 && strcmp (get (arg, "type"), "hggroup"))
73 if (! isfield (obj, "contourmatrix"))
74 error ("clabel: expecting the handle to be a contour group");
84 if (length(varargin) > 0 && isnumeric (varargin{1}))
91 for i = 1 : length (varargin) - 1
93 if (strcmpi (arg, "labelspacing"))
94 label_spacing = varargin{i+1};
95 have_labelspacing = true;
101 for i = 1 : length (varargin)
103 if (strcmpi (arg, "manual"))
104 error ("clabel: manual contouring mode not supported");
110 if (have_labelspacing)
111 set (hg, "textlistmode", "manual", "textlist", v,
112 "labelspacing", label_spacing, "showtext", "on");
114 set (hg, "textlistmode", "manual", "textlist", v, "showtext", "on");
117 if (have_labelspacing)
118 set (hg,"showtext", "on", "labelspacing", label_spacing);
120 set (hg,"showtext", "on");
123 retval = findobj (hg, "type", "text");
124 if (! isempty (varargin))
125 set (retval, varargin {:});
128 retval = __clabel__ (c, v, hparent, label_spacing, [], varargin{:});
135 %! [c, h] = contour (peaks(), -4:6);
136 %! clabel (c, h, -4:2:6, "fontsize", 12);
140 %! [c, h] = contourf (peaks(), -7:6);
141 %! clabel (c, h, -6:2:6, "fontsize", 12);