# HG changeset patch # User jwe # Date 1106625421 0 # Node ID 67320fb4ae5caf97b7dbe74d6ccf1839b42b9428 # Parent 57372235194b0003e0924b071cd16a55bc7cb5f6 [project @ 2005-01-25 03:57:01 by jwe] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,10 @@ 2005-01-24 John W. Eaton + * plot/__plr__.m, plot/__plr2__.m: Pass name of caller to __plt__. + + * plot/__plt__.m: No need to save and reset hold state now. + (first_plot): Delete unused variable. + * plot/__plr2__.m, plot/__plt2__.m: Improve diagnostics. * plot/__plr__.m: Use __plt__, not specific __pltXX__ functions. diff --git a/scripts/plot/__plr2__.m b/scripts/plot/__plr2__.m --- a/scripts/plot/__plr2__.m +++ b/scripts/plot/__plr2__.m @@ -41,7 +41,7 @@ if (isscalar (rho)) x = rho * cos (theta); y = rho * sin (theta); - __plt__ (x, y, fmt); + __plt__ ("polar", x, y, fmt); else error ("__plr2__: invalid data for plotting"); endif @@ -58,7 +58,7 @@ endif x = rho .* cos (theta); y = rho .* sin (theta); - __plt__ (x, y, fmt); + __plt__ ("polar", x, y, fmt); elseif (ismatrix (rho)) [t_nr, t_nc] = size (theta); if (t_nr == 1) @@ -79,7 +79,7 @@ endif x = diag (cos (theta)) * rho; y = diag (sin (theta)) * rho; - __plt__ (x, y, fmt); + __plt__ ("polar", x, y, fmt); else error ("__plr2__: invalid data for plotting") endif @@ -105,14 +105,14 @@ diag_r = diag (rho); x = diag_r * cos (theta); y = diag_r * sin (theta); - __plt__ (x, y, fmt); + __plt__ ("polar", x, y, fmt); elseif (ismatrix (rho)) if (size (rho) != size (theta)) error ("__plr2__: matrix dimensions must match"); endif x = rho .* cos (theta); y = rho .* sin (theta); - __plt__ (x, y, fmt); + __plt__ ("polar", x, y, fmt); else error ("__plr2__: invalid data for plotting") endif diff --git a/scripts/plot/__plr__.m b/scripts/plot/__plr__.m --- a/scripts/plot/__plr__.m +++ b/scripts/plot/__plr__.m @@ -59,7 +59,7 @@ if (isscalar (rho)) x = rho * cos (theta); y = rho * sin (theta); - __plt__ (x, y, fmt); + __plt__ ("polar", x, y, fmt); endif elseif (isvector (theta)) if (isvector (rho)) @@ -74,7 +74,7 @@ endif x = rho .* cos (theta); y = rho .* sin (theta); - __plt__ (x, y, fmt); + __plt__ ("polar", x, y, fmt); elseif (ismatrix (rho)) [t_nr, t_nc] = size (theta); if (t_nr == 1) @@ -95,7 +95,7 @@ endif x = diag (cos (theta)) * rho; y = diag (sin (theta)) * rho; - __plt__ (x, y, fmt); + __plt__ ("polar", x, y, fmt); endif elseif (ismatrix (theta)) if (isvector (rho)) @@ -119,14 +119,14 @@ diag_r = diag (r); x = diag_r * cos (theta); y = diag_r * sin (theta); - __plt__ (x, y, fmt); + __plt__ ("polar", x, y, fmt); elseif (ismatrix (rho)) if (size (rho) != size (theta)) error ("polar: matrix dimensions must match"); endif x = rho .* cos (theta); y = rho .* sin (theta); - __plt__ (x, y, fmt); + __plt__ ("polar", x, y, fmt); endif endif else diff --git a/scripts/plot/__plt__.m b/scripts/plot/__plt__.m --- a/scripts/plot/__plt__.m +++ b/scripts/plot/__plt__.m @@ -29,91 +29,38 @@ if (nargs >= 2) - first_plot = 1; - hold_state = ishold (); - - unwind_protect + k = 1; + j = 1; + x = varargin{k++}; + nargs -= 2; + x_set = 1; + y_set = 0; + gp_cmd = "gplot"; + have_gp_cmd = false; - k = 1; - j = 1; - x = varargin{k++}; - nargs -= 2; - x_set = 1; - y_set = 0; - gp_cmd = "gplot"; - have_gp_cmd = false; - - ## Gather arguments, decode format, gather plot strings, and plot lines. + ## Gather arguments, decode format, gather plot strings, and plot lines. - while (nargs-- > 0) - - fmt = ""; - new = varargin{k++}; + while (nargs-- > 0) - if (j > 1) - sep = ",\\\n"; - else - sep = ""; - endif + fmt = ""; + new = varargin{k++}; - if (isstr (new)) - if (! x_set) - error ("plot: no data to plot"); - endif - fmt = __pltopt__ (caller, new); - if (! y_set) - [data{j}, fmtstr] = __plt1__ (x, fmt); - else - [data{j}, fmtstr] = __plt2__ (x, y, fmt); - endif - if (iscell (data{j})) - for i = 1:length (data{j}) - gp_cmd = sprintf ("%s%s data{%d}{%d} %s", gp_cmd, sep, - j, i, fmtstr{i}); - sep = ",\\\n"; - have_gp_cmd = true; - endfor - else - gp_cmd = sprintf ("%s%s data{%d} %s", gp_cmd, sep, j++, fmtstr); - have_gp_cmd = true; - endif - x_set = 0; - y_set = 0; - elseif (x_set) - if (y_set) - [data{j}, fmtstr] = __plt2__ (x, y, fmt); - if (iscell (data{j})) - for i = 1:length (data{j}) - gp_cmd = sprintf ("%s%s data{%d}{%d} %s", gp_cmd, sep, - j, i, fmtstr{i}); - sep = ",\\\n"; - have_gp_cmd = true; - endfor - else - gp_cmd = sprintf ("%s%s data{%d} %s", gp_cmd, sep, j++, fmtstr); - have_gp_cmd = true; - endif - x = new; - y_set = 0; - else - y = new; - y_set = 1; - endif - else - x = new; - x_set = 1; - endif + if (j > 1) + sep = ",\\\n"; + else + sep = ""; + endif - endwhile - - ## Handle last plot. - - if (x_set) - if (y_set) - [data{j}, fmtstr] = __plt2__ (x, y, fmt); - else - [data{j}, fmtstr] = __plt1__ (x, fmt); - endif + if (isstr (new)) + if (! x_set) + error ("plot: no data to plot"); + endif + fmt = __pltopt__ (caller, new); + if (! y_set) + [data{j}, fmtstr] = __plt1__ (x, fmt); + else + [data{j}, fmtstr] = __plt2__ (x, y, fmt); + endif if (iscell (data{j})) for i = 1:length (data{j}) gp_cmd = sprintf ("%s%s data{%d}{%d} %s", gp_cmd, sep, @@ -124,29 +71,66 @@ else gp_cmd = sprintf ("%s%s data{%d} %s", gp_cmd, sep, j++, fmtstr); have_gp_cmd = true; - endif - endif - - if (have_gp_cmd) - eval (gp_cmd); + endif + x_set = 0; + y_set = 0; + elseif (x_set) + if (y_set) + [data{j}, fmtstr] = __plt2__ (x, y, fmt); + if (iscell (data{j})) + for i = 1:length (data{j}) + gp_cmd = sprintf ("%s%s data{%d}{%d} %s", gp_cmd, sep, + j, i, fmtstr{i}); + sep = ",\\\n"; + have_gp_cmd = true; + endfor + else + gp_cmd = sprintf ("%s%s data{%d} %s", gp_cmd, sep, j++, fmtstr); + have_gp_cmd = true; + endif + x = new; + y_set = 0; + else + y = new; + y_set = 1; + endif + else + x = new; + x_set = 1; endif - unwind_protect_cleanup + endwhile + + ## Handle last plot. - if (! hold_state) - hold off; + if (x_set) + if (y_set) + [data{j}, fmtstr] = __plt2__ (x, y, fmt); + else + [data{j}, fmtstr] = __plt1__ (x, fmt); endif - - end_unwind_protect + if (iscell (data{j})) + for i = 1:length (data{j}) + gp_cmd = sprintf ("%s%s data{%d}{%d} %s", gp_cmd, sep, + j, i, fmtstr{i}); + sep = ",\\\n"; + have_gp_cmd = true; + endfor + else + gp_cmd = sprintf ("%s%s data{%d} %s", gp_cmd, sep, j++, fmtstr); + have_gp_cmd = true; + endif + endif + if (have_gp_cmd) + eval (gp_cmd); + endif else - msg = sprintf ("%s (x)\n", caller); msg = sprintf ("%s %s (x, y)\n", msg, caller); msg = sprintf ("%s %s (x2, y1, x2, y2)\n", msg, caller); msg = sprintf ("%s %s (x, y, fmt)", msg, caller); usage (msg); - endif endfunction