Mercurial > hg > octave-max
changeset 7175:5ff4da7bd2e7
[project @ 2007-11-14 20:36:48 by jwe]
author | jwe |
---|---|
date | Wed, 14 Nov 2007 20:36:48 +0000 |
parents | ff4a4cc863a9 |
children | 6525eb2fba0f |
files | scripts/ChangeLog scripts/plot/Makefile.in scripts/plot/__contour__.m scripts/plot/__go_draw_axes__.m scripts/plot/contour3.m scripts/plot/surface.m |
diffstat | 6 files changed, 206 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,18 @@ +2007-11-14 David Bateman <dbateman@free.fr> + + * plot/__contour__.m: Treat unclosed contours by adding NaN to + flag to patch that it is not closed. Allow z to take string + arguments and use it to flag that the contours are placed at the + z level of the contour itself. + * plot/__go_draw_axes__.m: Treat hidden line removal in patch + objects as well. Let hidden removal take precedence in case of a + conflict. + * plot/surface.m: Allow surface to treat handles being passed or + returned. Any additional arguments arr used to set the surface + handle. + * plot/contour3.m: New function + * plot/Makefile.in (SOURCES): Add it to the sources. + 2007-11-14 John W. Eaton <jwe@octave.org> * specfun/bessel.m: Update doc string from
--- a/scripts/plot/Makefile.in +++ b/scripts/plot/Makefile.in @@ -72,6 +72,7 @@ clf.m \ close.m \ closereq.m \ + contour3.m \ contour.m \ contourc.m \ contourf.m \
--- a/scripts/plot/__contour__.m +++ b/scripts/plot/__contour__.m @@ -23,6 +23,21 @@ ax = varargin {1}; z = varargin {2}; + if (ischar (z)) + if (strcmp (z, "none")) + z = NaN; + elseif (strcmp (z, "base")) + if (nargin == 1) + z = varargin {1}; + else + z = varargin {3}; + endif + z = 2 * (min(z(:)) - max(z(:))); + elseif (!strcmp (z, "level")) + error ("unrecognized z argument"); + endif + endif + clim = get (ax, "clim"); [c, lev] = contourc (varargin{3:end}); @@ -36,15 +51,23 @@ clev = c(1,i1); clen = c(2,i1); - ii = i1+1:i1+clen; + if (all (c(:,i1+1) == c(:,i1+clen))) + p = c(:, i1+1:i1+clen-1); + else + p = [c(:, i1+1:i1+clen), NaN(2, 1)]; + endif + lev = (clev - minlev) * (clim(2) - clim(1)) / (maxlev - minlev) + clim(1); if (isnan (z)) - h = [h; patch(ax, c(1,ii), c(2,ii), "facecolor", "none", + h = [h; patch(ax, p(1,:), p(2,:), "facecolor", "none", "edgecolor", "flat", "cdata", lev)]; + elseif (!ischar(z)) + h = [h; patch(ax, p(1,:), p(2,:), z * ones (1, columns (p)), "facecolor", + "none", "edgecolor", "flat", "cdata", lev)]; else - h = [h; patch(ax, c(1,ii), c(2,ii), z*ones(size(ii)), "facecolor", - "none", "edgecolor", "flat", "cdata", lev)]; + h = [h; patch(ax, p(1,:), p(2,:), clev * ones (1, columns (p)), + "facecolor", "none", "edgecolor", "flat", "cdata", lev)]; endif i1 += clen+1; endwhile
--- a/scripts/plot/__go_draw_axes__.m +++ b/scripts/plot/__go_draw_axes__.m @@ -204,7 +204,7 @@ data_idx = 0; data = cell (); is_image_data = []; - hidden_removal = true; + hidden_removal = NaN; xminp = yminp = zminp = cminp = Inf; xmax = ymax = zmax = cmax = -Inf; @@ -461,7 +461,12 @@ if (! isnan (xcol) && ! isnan (ycol)) ## Is the patch closed or not - if (! strncmp (obj.facecolor, "none", 4)) + if (strncmp (obj.facecolor, "none", 4)) + if (isnan (hidden_removal)) + hidden_removal = false; + endif + else + hidden_removal = true; if (! isempty (zcol)) error ("gnuplot (as of v4.2) only supports 2D filled patches"); else @@ -747,7 +752,11 @@ palette_data = []; if (strncmp (obj.facecolor, "none", 4)) - hidden_removal = false; + if (isnan (hidden_removal)) + hidden_removal = false; + endif + else + hidden_removal = true; endif if (flat_interp_face @@ -895,7 +904,7 @@ endfor - if (hidden_removal) + if (isnan(hidden_removal) || hidden_removal) fputs (plot_stream, "set hidden3d;\n"); else fputs (plot_stream, "unset hidden3d;\n");
new file mode 100644 --- /dev/null +++ b/scripts/plot/contour3.m @@ -0,0 +1,77 @@ +## Copyright (C) 2007 David BAteman +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{c} =} contour3 (@var{z}) +## @deftypefnx {Function File} {@var{c} =} contour3 (@var{z}, @var{vn}) +## @deftypefnx {Function File} {@var{c} =} contour3 (@var{x}, @var{y}, @var{z}) +## @deftypefnx {Function File} {@var{c} =} contour3 (@var{x}, @var{y}, @var{z}, @var{vn}) +## @deftypefnx {Function File} {@var{c} =} contour3 (@var{h}, @dots{}) +## @deftypefnx {Function File} {[@var{c}, @var{h}] =} contour3 (@dots{}) +## Plot level curves (contour lines) of the matrix @var{z}, using the +## contour matrix @var{c} computed by @code{contourc} from the same +## arguments; see the latter for their interpretation. The contours are +## ploted at the Z level corresponding to their contour. The set of +## contour levels, @var{c}, is only returned if requested. For example: +## +## @example +## @group +## contour3 (peaks (19)); +## hold on +## surface (peaks (19), 'FaceColor', 'none', 'EdgeColor', 'black') +## colormap hot +## @end group +## @end example +## +## The optional input and output argument @var{h} allows an axis handle to +## be passed to @code{contour} and the handles to the contour objects to be +## returned. +## @seealso{contourc, patch, plot} +## @end deftypefn + +function [c, h] = contour3 (varargin) + + if (isscalar (varargin{1}) && ishandle (varargin{1})) + ax = varargin{1}; + if (! strcmp (get (ax, "type"), "axes")) + error ("contour: expecting first argument to be an axes object"); + endif + oldh = gca (); + unwind_protect + axes (ax); + newplot (); + [ctmp, htmp] = __contour__ (ax, varargin{2:end}); + unwind_protect_cleanup + axes (oldh); + end_unwind_protect + else + newplot (); + ax = gca (); + [ctmp, htmp] = __contour__ (ax, "level", varargin{:}); + endif + + if (! ishold ()) + set (ax, "view", [-37.5, 30]); + endif + + if (nargout > 0) + c = ctmp; + h = htmp + endif + +endfunction
--- a/scripts/plot/surface.m +++ b/scripts/plot/surface.m @@ -18,49 +18,48 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} @var{h} = {} surface (@var{x}, @var{y}, @var{z}, @var{c}) -## @deftypefnx {Function File} @var{h} = {} surface (@var{x}, @var{y}, @var{z}) -## Plot a surface graphic object given matrices @var{x}, and @var{y} from @code{meshgrid} and -## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of -## the surface. If @var{x} and @var{y} are vectors, then a typical vertex -## is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns of @var{z} -## correspond to different @var{x} values and rows of @var{z} correspond -## to different @var{y} values. +## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c}) +## @deftypefnx {Function File} {} surface (@var{x}, @var{y}, @var{z}) +## @deftypefnx {Function File} {} surface (@var{z}, @var{c}) +## @deftypefnx {Function File} {} surface (@var{z}) +## @deftypefnx {Function File} {} surface (@dots{}, @var{prop}, @var{val}) +## @deftypefnx {Function File} {} surface (@var{h}, @dots{}) +## @deftypefnx {Function File} {@var{h} = } surface (@dots{}) +## Plot a surface graphic object given matrices @var{x}, and @var{y} from +## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and +## @var{y} coordinates of the surface. If @var{x} and @var{y} are vectors, +## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, +## columns of @var{z} correspond to different @var{x} values and rows of +## @var{z} correspond to different @var{y} values. If @var{x} and @var{y} +## are missing, they are constructed from size of the matrix @var{z}. +## +## Any additional properties passed are assigned the the surface.. ## @seealso{surf, mesh, patch, line} ## @end deftypefn ## Author: jwe -function h = surface (x, y, z, c) +function h = surface (varargin) ax = gca (); - if (nargin == 1) - c = z = x; - if (ismatrix (z)) - [nr, nc] = size (z); - x = 1:nc; - y = (1:nr)'; - else - error ("surface: argument must be a matrix"); + firststring = nargin + 1; + for i = 1 : nargin + if (ischar (varargin {i})) + firststring = i; + break; endif - elseif (nargin == 3) - c = z; - if (isvector (x) && isvector (y) && ismatrix (z)) - if (rows (z) == length (y) && columns (z) == length (x)) - x = x(:)'; - y = y(:); - else - error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); - endif - elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) - if (! (size_equal (x, y) && size_equal (x, z))) - error ("surface: x, y, and z must have same dimensions"); - endif - else - error ("surface: x and y must be vectors and z must be a matrix"); - endif - elseif (nargin == 4) + endfor + + + if (firststring > 5) + print_usage (); + elseif (firststring == 5) + x = varargin{1}; + y = varargin{2}; + z = varargin{3}; + c = varargin{4}; + if (! size_equal (z, c)) error ("surface: z and c must have same size"); endif @@ -78,6 +77,45 @@ else error ("surface: x and y must be vectors and z must be a matrix"); endif + elseif (firststring == 4) + x = varargin{1}; + y = varargin{2}; + z = varargin{3}; + c = z; + if (isvector (x) && isvector (y) && ismatrix (z)) + if (rows (z) == length (y) && columns (z) == length (x)) + x = x(:)'; + y = y(:); + else + error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); + endif + elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) + if (! (size_equal (x, y) && size_equal (x, z))) + error ("surface: x, y, and z must have same dimensions"); + endif + else + error ("surface: x and y must be vectors and z must be a matrix"); + endif + elseif (firststring == 3) + z = varargin {1}; + c = varargin {2}; + if (ismatrix (z)) + [nr, nc] = size (z); + x = 1:nc; + y = (1:nr)'; + else + error ("surface: argument must be a matrix"); + endif + elseif (firststring == 2) + z = varargin {1}; + c = z; + if (ismatrix (z)) + [nr, nc] = size (z); + x = 1:nc; + y = (1:nr)'; + else + error ("surface: argument must be a matrix"); + endif else print_usage (); endif @@ -85,6 +123,7 @@ ## Make a default surface object. tmp = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c); set (tmp, "facecolor","flat"); + set (tmp, varargin {firststring:end}); if (! ishold ()) set (ax, "view", [0, 90], "box", "off", "xgrid", "on", "ygrid", "on", "zgrid", "on");