# HG changeset patch # User jwe # Date 1194469745 0 # Node ID d22ad51b9cf8f908bb5be4b5bb50fe5ee073f446 # Parent d32f867e4ddac0d4acb7ff2d49e2fa752c3256d5 [project @ 2007-11-07 21:06:27 by jwe] diff -r d32f867e4dda -r d22ad51b9cf8 scripts/ChangeLog --- a/scripts/ChangeLog Wed Nov 07 20:44:29 2007 +0000 +++ b/scripts/ChangeLog Wed Nov 07 21:09:05 2007 +0000 @@ -1,5 +1,9 @@ 2007-11-07 David Bateman + * plot/__go_draw_axes__.m: Fix surfaces for gnuplot 4.0 and for + the meshc.m function. + * plot/meshc.m: Also use the surface function. + * plot/surfc.m, plot/meshc.m: New files. * plot/Makefile.in (SOURCES): Add them to the list. Also add pcolor.m, shading.m, surf.m, and surface.m to the list. diff -r d32f867e4dda -r d22ad51b9cf8 scripts/plot/__go_draw_axes__.m --- a/scripts/plot/__go_draw_axes__.m Wed Nov 07 20:44:29 2007 +0000 +++ b/scripts/plot/__go_draw_axes__.m Wed Nov 07 21:09:05 2007 +0000 @@ -237,6 +237,7 @@ data_idx++; is_image_data(data_idx) = true; parametric(data_idx) = false; + have_cdata(data_idx) = false; [y_dim, x_dim] = size (img_data(:,:,1)); if (x_dim > 1) @@ -300,6 +301,7 @@ data_idx++; is_image_data(data_idx) = false; parametric(data_idx) = true; + have_cdata(data_idx) = false; if (isempty (obj.keylabel)) titlespec{data_idx} = "title \"\""; else @@ -320,6 +322,7 @@ xdat = obj.xdata(:); ydat = obj.ydata(:); zdat = obj.zdata(:); + if (xautoscale) [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat); endif @@ -332,7 +335,7 @@ data{data_idx} = [xdat, ydat, zdat]'; usingclause{data_idx} = "using ($1):($2):($3)"; fputs (plot_stream, "set parametric;\n"); - fputs (plot_stream, "unset hidden3d;\n"); + fputs (plot_stream, "set hidden3d;\n"); fputs (plot_stream, "set style data lines;\n"); fputs (plot_stream, "set surface;\n"); fputs (plot_stream, "unset contour;\n"); @@ -446,18 +449,19 @@ data_idx++; is_image_data(data_idx) = false; parametric(data_idx) = false; + have_cdata(data_idx) = false; titlespec{data_idx} = "title \"\""; usingclause{data_idx} = ""; if (isfield (obj, "facecolor") && isfield (obj, "cdata")) if (strncmp (obj.facecolor, "none", 4)) color = [1, 1, 1]; - elseif (strncmp (obj.facecolor, "flat", 4) || - strncmp (obj.facecolor, "interp", 6)) - if (ndims (obj.cdata) == 2 && ... - ((nr > 3 && size (obj.cdata, 2) == nc) ... - || (size (obj.cdata, 1) > 1 && ... - size (obj.cdata, 2) == nc))) + elseif (strncmp (obj.facecolor, "flat", 4) + || strncmp (obj.facecolor, "interp", 6)) + if (ndims (obj.cdata) == 2 + && ((nr > 3 && size (obj.cdata, 2) == nc) + || (size (obj.cdata, 1) > 1 + && size (obj.cdata, 2) == nc))) ccol = obj.cdata (:, i); elseif (ndims (obj.cdata) == 3) ccol = permute (obj.cdata (:, i, :), [1, 3, 2]); @@ -468,8 +472,8 @@ if (numel(ccol) == 3) color = ccol; else - r = 1 + round ((size (cmap, 1) - 1) * ... - (ccol - clim(1))/(clim(2) - clim(1))); + r = 1 + round ((size (cmap, 1) - 1) + * (ccol - clim(1))/(clim(2) - clim(1))); r = max (1, min (r, size (cmap, 1))); color = cmap(r, :); endif @@ -487,9 +491,9 @@ endif if (have_newer_gnuplot) - withclause{data_idx} = ... - sprintf ("with filledcurve lc rgb \"#%02x%02x%02x\"", ... - round (255*color)); + withclause{data_idx} ... + = sprintf ("with filledcurve lc rgb \"#%02x%02x%02x\"", + round (255*color)); else if (isequal (color, [0,0,0])) typ = -1; @@ -520,6 +524,7 @@ data_idx++; is_image_data(data_idx) = false; parametric(data_idx) = false; + have_cdata(data_idx) = false; titlespec{data_idx} = "title \"\""; usingclause{data_idx} = ""; if (isfield (obj, "edgecolor")) @@ -538,9 +543,9 @@ color = [0, 0, 0]; endif if (have_newer_gnuplot) - withclause{data_idx} = ... - sprintf ("with lines lc rgb \"#%02x%02x%02x\"", ... - round (255*color)); + withclause{data_idx} ... + = sprintf ("with lines lc rgb \"#%02x%02x%02x\"", + round (255*color)); else if (isequal (color, [0,0,0])) typ = -1; @@ -564,7 +569,7 @@ withclause{data_idx} = sprintf ("with lines lt %d", typ); endif - if (!isnan (xcol) && !isnan (ycol)) + if (!isnan (xcol) && ! isnan (ycol)) data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]'; else data{data_idx} = [xcol, ycol]'; @@ -573,12 +578,13 @@ endfor case "surface" - nd = 4; + nd = 3; if (! (strncmp (obj.edgecolor, "none", 4) && strncmp (obj.facecolor, "none", 4))) data_idx++; is_image_data(data_idx) = false; parametric(data_idx) = false; + have_cdata(data_idx) = true; [style, typ, with] = do_linestyle_command (obj, data_idx, plot_stream); if (isempty (obj.keylabel)) titlespec{data_idx} = "title \"\""; @@ -664,49 +670,75 @@ fputs (plot_stream, "unset contour;\n"); fprintf (plot_stream, "set cbrange [%g:%g];\n", cmin, cmax); - if (have_newer_gnuplot) - ## Interpolation does not work for flat surfaces (e.g. pcolor) - ## and color mapping --> currently set empty. - interp_str = ""; - surf_colormap = parent_figure_obj.colormap; - flat_interp_face = (strncmp (obj.facecolor, "flat", 4) - || strncmp (obj.facecolor, "interp", 6)); - flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4) - || strncmp (obj.edgecolor, "interp", 6)); - palette_data = []; + ## Interpolation does not work for flat surfaces (e.g. pcolor) + ## and color mapping --> currently set empty. + interp_str = ""; + surf_colormap = parent_figure_obj.colormap; + flat_interp_face = (strncmp (obj.facecolor, "flat", 4) + || strncmp (obj.facecolor, "interp", 6)); + flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4) + || strncmp (obj.edgecolor, "interp", 6)); + palette_data = []; + + if (flat_interp_face + || (flat_interp_edge && strncmp (obj.facecolor, "none", 4))) + palette_data = [1:rows(surf_colormap); surf_colormap']; + endif - if (flat_interp_face - || (flat_interp_edge && strncmp (obj.facecolor, "none", 4))) - palette_data = [1:rows(surf_colormap); surf_colormap']; - endif + if (isnumeric (obj.facecolor)) + palette_data = [1:2; [obj.facecolor; obj.facecolor]']; + endif - if (isnumeric (obj.facecolor)) - palette_data = [1:2; [obj.facecolor; obj.facecolor]']; - endif + if (strncmp (obj.facecolor, "none", 4) + && isnumeric (obj.edgecolor)) + palette_data = [1:2; [obj.edgecolor; obj.edgecolor]']; + endif - if (strncmp (obj.facecolor, "none", 4) - && isnumeric (obj.edgecolor)) - palette_data = [1:2; [obj.edgecolor; obj.edgecolor]']; - endif - - if (strncmp (obj.facecolor, "none", 4)) - elseif (flat_interp_face && strncmp (obj.edgecolor, "flat", 4)) + if (strncmp (obj.facecolor, "none", 4)) + elseif (flat_interp_face && strncmp (obj.edgecolor, "flat", 4)) + fprintf (plot_stream, "set pm3d at s %s;\n", interp_str); + else + if (strncmp (obj.edgecolor, "none", 4)) fprintf (plot_stream, "set pm3d at s %s;\n", interp_str); else - if (strncmp(obj.edgecolor, "none", 4)) - fprintf (plot_stream, "set pm3d at s %s;\n", interp_str); - else - edgecol = obj.edgecolor; - if (ischar(obj.edgecolor)) - edgecol = [0 0 0]; - endif - fprintf (plot_stream, "set pm3d at s hidden3d %d %s;\n", data_idx, interp_str); + edgecol = obj.edgecolor; + if (ischar (obj.edgecolor)) + edgecol = [0,0,0]; + endif + fprintf (plot_stream, "set pm3d at s hidden3d %d %s;\n", data_idx, interp_str); + + if (have_newer_gnuplot) fprintf (plot_stream, "set style line %d linecolor rgb \"#%02x%02x%02x\" lw %f;\n", data_idx, round (255*edgecol), obj.linewidth); - endif + else + if (isequal (edgecol, [0,0,0])) + typ = -1; + elseif (isequal (edgecol, [1,0,0])) + typ = 1; + elseif (isequal (edgecol, [0,1,0])) + typ = 2; + elseif (isequal (edgecol, [0,0,1])) + typ = 3; + elseif (isequal (edgecol, [1,0,1])) + typ = 4; + elseif (isequal (edgecol, [0,1,1])) + typ = 5; + elseif (isequal (edgecol, [1,1,1])) + typ = -1; + elseif (isequal (edgecol, [1,1,0])) + typ = 7; + else + typ = -1; + endif + fprintf (plot_stream, + "set style line %d lt %d lw %f;\n", + data_idx, typ, obj.linewidth); + endif endif + endif + if (have_newer_gnuplot) if (length(palette_data) > 0) fprintf (plot_stream, "set palette positive color model RGB maxcolors %i;\n", @@ -821,7 +853,7 @@ fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", yaxisloc, ylim, ydir); - if (nd == 3 || nd == 4) + if (nd == 3) if (zautoscale && have_data) zlim = get_axis_limits (zmin, zmax, zminp, zlogscale); if (isempty (zlim)) @@ -840,13 +872,13 @@ endif if (strcmpi (axis_obj.box, "on")) - if (nd == 3 || nd == 4) + if (nd == 3) fputs (plot_stream, "set border 4095;\n"); else fputs (plot_stream, "set border 431;\n"); endif else - if (nd == 3 || nd == 4) + if (nd == 3) fputs (plot_stream, "set border 895;\n"); else fputs (plot_stream, "set border 3;\n"); @@ -871,7 +903,7 @@ keyout = findstr (keypos, "outside"); if (! isempty (keyout)) inout = "outside"; - keypos = keypos (1:keyout-1); + keypos = keypos(1:keyout-1); endif endif switch (keypos) @@ -951,7 +983,8 @@ if (is_image_data(i)) fwrite (plot_stream, data{i}, "float32"); else - __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i)); + __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i), + have_cdata(i)); endif endfor else @@ -967,7 +1000,7 @@ endfunction function [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat, tx) - if (! (isempty (xdat) || isempty (tx))) + if (! (isempty (xdat) || (nargin > 4 && isempty (tx)))) xdat = xdat(! isinf (xdat)); xmin = min (xmin, min (xdat)); xmax = max (xmax, max (xdat)); @@ -1190,7 +1223,7 @@ endfunction -function __gnuplot_write_data__ (plot_stream, data, nd, parametric) +function __gnuplot_write_data__ (plot_stream, data, nd, parametric, cdata) ## DATA is already transposed. @@ -1228,21 +1261,17 @@ fprintf (plot_stream, "%.15g %.15g %.15g\n", data); else nc = columns (data); - for j = 1:3:nc - fprintf (plot_stream, "%.15g %.15g %.15g\n", data(:,j:j+2)'); - fputs (plot_stream, "\n"); - endfor - endif - elseif (nd == 4) - ## FIXME -- handle NaNs here too? - if (parametric) - fprintf (plot_stream, "%.15g %.15g %.15g\n", data); - else - nc = columns (data); - for j = 1:4:nc - fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data(:,j:j+3)'); - fputs (plot_stream, "\n"); - endfor + if (cdata) + for j = 1:4:nc + fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data(:,j:j+3)'); + fputs (plot_stream, "\n"); + endfor + else + for j = 1:3:nc + fprintf (plot_stream, "%.15g %.15g %.15g\n", data(:,j:j+2)'); + fputs (plot_stream, "\n"); + endfor + endif endif endif fputs (plot_stream, "e\n"); diff -r d32f867e4dda -r d22ad51b9cf8 scripts/plot/meshc.m --- a/scripts/plot/meshc.m Wed Nov 07 20:44:29 2007 +0000 +++ b/scripts/plot/meshc.m Wed Nov 07 21:09:05 2007 +0000 @@ -31,53 +31,20 @@ newplot (); - if (nargin == 1) - z = varargin{1}; - if (ismatrix (z)) - [nr, nc] = size (z); - x = 1:nc; - y = (1:nr)'; - else - error ("meshc: argument must be a matrix"); - endif - elseif (nargin == 3) - x = varargin{1}; - y = varargin{2}; - z = varargin{3}; + tmp = surface (varargin{:}); + + ax = get (tmp, "parent"); - if (isvector (x) && isvector (y) && ismatrix (z)) - if (rows (z) == length (y) && columns (z) == length (x)) - x = x(:)'; - y = y(:); - else - msg = "meshc: rows (z) must be the same as length (y) and"; - msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); - error (msg); - endif - elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) - if (! (size_equal (x, y) && size_equal (x, z))) - error ("meshc: x, y, and z must have same dimensions"); - endif - else - error ("meshc: x and y must be vectors and z must be a matrix"); - endif - else - print_usage (); - endif + set (tmp, "facecolor", "none"); + set (tmp, "edgecolor", "flat"); - ## make a default line object, and make it the current axes for the - ## current figure. - ca = gca (); - - tmp = __go_surface__ (ca, "xdata", x, "ydata", y, "zdata", z); - - set (ca, "view", [-37.5, 30]); + set (ax, "view", [-37.5, 30]); hold on; [c, lev] = contourc (varargin{:}); - cmap = get (gcf(), "colormap"); + cmap = get (gcf (), "colormap"); levx = linspace (min (lev), max (lev), size (cmap, 1)); @@ -85,7 +52,7 @@ ax = axis(); zmin = 2 * ax(5) - ax(6); - ## decode contourc output format + ## Decode contourc output format. i1 = 1; while (i1 < length (c)) @@ -97,12 +64,15 @@ ccb = interp1 (levx, cmap(:,3), clev); ii = i1+1:i1+clen; - line (c(1,ii), c(2,ii), zmin*ones(size(ii)), "color", [ccr, ccg, ccb]); + line (c(1,ii), c(2,ii), zmin * ones (size (ii)), "color", + [ccr, ccg, ccb]); i1 += c(2,i1)+1; + endwhile if (nargout > 0) h = tmp; endif + endfunction diff -r d32f867e4dda -r d22ad51b9cf8 scripts/plot/pie.m --- a/scripts/plot/pie.m Wed Nov 07 20:44:29 2007 +0000 +++ b/scripts/plot/pie.m Wed Nov 07 21:09:05 2007 +0000 @@ -67,9 +67,11 @@ if (nargout > 0) retval = tmp; endif + endfunction function hlist = __pie__ (varargin) + h = varargin{1}; x = abs (varargin{2}); iarg = 3; @@ -81,7 +83,7 @@ len = length (x); while (iarg <= nargin) - arg = varargin {iarg++}; + arg = varargin{iarg++}; if (iscell (arg)) labels = arg; if (! size_equal (x, labels)) @@ -101,23 +103,23 @@ if (! exist ("labels", "var")) xp = round (100 * x ./ sum (x)); - for i = 1 : len + for i = 1:len labels{i} = sprintf ("%d%%", xp(i)); endfor endif hlist = []; refinement = 90; - phi = 0 : refinement : 360; - xphi = cumsum (x / sum(x) * 360); - for i = 1 : len + phi = 0:refinement:360; + xphi = cumsum (x / sum (x) * 360); + for i = 1:len if (i == 1) xn = 0 : 360 / refinement : xphi(i); else xn = xphi(i-1) : 360 / refinement : xphi(i); endif - if (xn (length (xn)) != xphi(i)) + if (xn(end) != xphi(i)) xn = [xn, xphi(i)]; endif @@ -138,13 +140,16 @@ endif hlist = [hlist; patch(xoff + [0, - sind(xn)], yoff + [0, cosd(xn)], i); - text(xt, yt, labels {i}, "HorizontalAlignment", align)]; + text(xt, yt, labels {i}, "horizontalalignment", align)]; endfor + if (len == 1) set (h, "clim", [1, 2]); else set (h, "clim", [1, len]); endif - axis ([-1.5,1.5,-1.5,1.5]); + + axis ([-1.5, 1.5, -1.5, 1.5]); + endfunction