changeset 934:be867ddbe4aa

[project @ 1994-11-17 04:23:41 by jwe]
author jwe
date Thu, 17 Nov 1994 04:23:41 +0000
parents 598a3aa40360
children 28e275222873
files scripts/plot/__plr__.m scripts/plot/__plt2mm__.m scripts/plot/__plt2mv__.m scripts/plot/__plt2ss__.m scripts/plot/__plt2vm__.m scripts/plot/__plt2vv__.m scripts/plot/__plt__.m scripts/plot/loglog.m scripts/plot/plot.m scripts/plot/polar.m scripts/plot/semilogx.m scripts/plot/semilogy.m
diffstat 12 files changed, 190 insertions(+), 120 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/__plr__.m
+++ b/scripts/plot/__plr__.m
@@ -16,7 +16,7 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function polar_int (theta, rho)
+function polar_int (theta, rho, fmt)
 
   if (nargin == 1)
     [nr, nc] = size (theta);
@@ -27,7 +27,7 @@
       nc = tmp;
     endif
     theta_i = imag (theta);
-    if (theta_i)
+    if (any (theta_i))
       rho = theta_i;
       theta = real (theta);
     else
@@ -37,17 +37,17 @@
   endif
 
   if (nargin <= 2)
-    if (imag (theta))
+    if (any (imag (theta)))
       theta = real (theta);
     endif
-    if (imag (rho))
+    if (any (imag (rho)))
       rho = real (rho);
     endif
     if (is_scalar (theta))
       if (is_scalar (rho))
         x = rho * cos (theta);
         y = rho * sin (theta);
-        plot_2_s_s (x, y);
+        plot_2_s_s (x, y, fmt);
       endif
     elseif (is_vector (theta))
       if (is_vector (rho))
@@ -62,7 +62,7 @@
         endif
         x = rho .* cos (theta);
         y = rho .* sin (theta);
-        plot_2_v_v (x, y);
+        plot_2_v_v (x, y, fmt);
       elseif (is_matrix (rho))
         [t_nr, t_nc] = size (theta);
         if (t_nr == 1)
@@ -83,7 +83,7 @@
         endif
         x = diag (cos (theta)) * rho;
         y = diag (sin (theta)) * rho;
-        plot_2_v_m (x, y);
+        plot_2_v_m (x, y, fmt);
       endif
     elseif (is_matrix (theta))
       if (is_vector (rho))
@@ -107,14 +107,14 @@
         diag_r = diag (r);
         x = diag_r * cos (theta);
         y = diag_r * sin (theta);
-        plot_2_m_v (x, y);
+        plot_2_m_v (x, y, fmt);
       elseif (is_matrix (rho))
         if (size (rho) != size (theta))
           error ("polar: matrix dimensions must match");
         endif
         x = rho .* cos (theta);
         y = rho .* sin (theta);
-        plot_2_m_m (x, y);
+        plot_2_m_m (x, y, fmt);
       endif
     endif
   else
--- a/scripts/plot/__plt2mm__.m
+++ b/scripts/plot/__plt2mm__.m
@@ -16,10 +16,14 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function plot_2_m_m (x, y)
+function plot_2_m_m (x, y, fmt)
 
-  if (nargin != 2)
-    usage ("plot_2_m_m (x, y)");
+  if (nargin < 2 || nargin > 3)
+    msg = sprintf ("plot_2_m_m (x, y)\n");
+    msg = sprintf ("%s              plot_2_m_m (x, y, fmt)", msg);
+    usage (msg);
+  elseif (nargin == 2)
+    fmt = "";
   endif
 
   [x_nr, x_nc] = size (x);
@@ -28,11 +32,11 @@
   if (x_nr == y_nr && x_nc == y_nc)
     if (x_nc > 0)
       tmp = [x, y];
-      command = sprintf ("gplot tmp(:,%d:%d:%d)", 1, x_nc, x_nc+1);
+      cmd = sprintf ("gplot tmp(:,%d:%d:%d) %s", 1, x_nc, x_nc+1, fmt);
       for i = 2:x_nc
-        command = sprintf ("%s, tmp(:,%d:%d:%d)", command, i, x_nc, x_nc+i);
+        cmd = sprintf ("%s, tmp(:,%d:%d:%d) %s", cmd, i, x_nc, x_nc+i, fmt);
       endfor
-      eval (command);
+      eval (cmd);
     else
       error ("plot_2_m_m: arguments must be a matrices");
     endif
--- a/scripts/plot/__plt2mv__.m
+++ b/scripts/plot/__plt2mv__.m
@@ -16,10 +16,14 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function plot_2_m_v (x, y)
+function plot_2_m_v (x, y, fmt)
 
-  if (nargin != 2)
-    usage ("plot_2_m_v (x, y)");
+  if (nargin < 2 || nargin > 3)
+    msg = sprintf ("plot_2_m_v (x, y)\n");
+    msg = sprintf ("%s              plot_2_m_v (x, y, fmt)", msg);
+    usage (msg);
+  elseif (nargin == 2)
+    fmt = "";
   endif
 
   [x_nr, x_nc] = size (x);
@@ -45,11 +49,11 @@
 
   if (x_nc > 0)
     tmp = [x, y];
-    command = sprintf ("gplot tmp(:,%d:%d:%d)", 1, x_nc, x_nc+1);
+    cmd = sprintf ("gplot tmp(:,%d:%d:%d) %s", 1, x_nc, x_nc+1, fmt);
     for i = 2:x_nc
-      command = sprintf ("%s, tmp(:,%d:%d:%d)", command, i, x_nc-i+1, x_nc+1);
+      cmd = sprintf ("%s, tmp(:,%d:%d:%d) %s", cmd, i, x_nc-i+1, x_nc+1, fmt);
     endfor
-    eval (command);
+    eval (cmd);
   else
     error ("plot_2_m_v: arguments must be a matrices");
   endif
--- a/scripts/plot/__plt2ss__.m
+++ b/scripts/plot/__plt2ss__.m
@@ -16,10 +16,14 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function plot_2_s_s (x, y)
+function plot_2_s_s (x, y, fmt)
 
-  if (nargin != 2)
-    usage ("plot_2_s_s (x, y)");
+  if (nargin < 2 || nargin > 3)
+    msg = sprintf ("plot_2_s_s (x, y)");
+    msg = sprintf ("%s              plot_2_s_s (x, y, fmt)", msg);
+    usage (msg);
+  elseif (nargin == 2)
+    fmt = "";
   endif
 
   [x_nr, x_nc] = size (x);
@@ -27,8 +31,8 @@
 
   if (x_nr == 1 && x_nr == y_nr && x_nc == 1 && x_nc == y_nc)
     tmp = [x, y];
-    command = sprintf ("gplot tmp");
-    eval ("gplot tmp");
+    cmd = sprintf ("gplot tmp %s", fmt);
+    eval (cmd);
   else
     error ("plot_2_s_s: arguments must be scalars");
   endif
--- a/scripts/plot/__plt2vm__.m
+++ b/scripts/plot/__plt2vm__.m
@@ -16,10 +16,14 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function plot_2_v_m (x, y)
+function plot_2_v_m (x, y, fmt)
 
-  if (nargin != 2)
-    usage ("plot_2_v_m (x, y)");
+  if (nargin < 2 || nargin > 3)
+    msg = sprintf ("plot_2_v_m (x, y)\n");
+    msg = sprintf ("%s              plot_2_v_m (x, y, fmt)", msg);
+    usage (msg);
+  elseif (nargin == 2)
+    fmt = "";
   endif
 
   [x_nr, x_nc] = size (x);
@@ -45,11 +49,11 @@
 
   if (y_nc > 0)
     tmp = [x, y];
-    command = sprintf ("gplot tmp(:,%d:%d:%d)", 1, x_nc, x_nc+1);
+    cmd = sprintf ("gplot tmp(:,%d:%d:%d) %s", 1, x_nc, x_nc+1, fmt);
     for i = 2:y_nc
-      command = sprintf ("%s, tmp(:,%d:%d:%d)", command, 1, i, i+1);
+      cmd = sprintf ("%s, tmp(:,%d:%d:%d) %s", cmd, 1, i, i+1, fmt);
     endfor
-    eval (command);
+    eval (cmd);
   else
     error ("plot_2_v_m: arguments must be a matrices");
   endif
--- a/scripts/plot/__plt2vv__.m
+++ b/scripts/plot/__plt2vv__.m
@@ -16,10 +16,14 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function plot_2_v_v (x, y)
+function plot_2_v_v (x, y, fmt)
 
-  if (nargin != 2)
-    usage ("plot_2_m_m (x, y)");
+  if (nargin < 2 || nargin > 3)
+    msg = sprintf ("plot_2_v_v (x, y)\n");
+    msg = sprintf ("%s              plot_2_v_v (x, y, fmt)", msg);
+    usage (msg);
+  elseif (nargin == 2)
+    fmt = "";
   endif
 
   [x_nr, x_nc] = size (x);
@@ -44,6 +48,7 @@
   endif
 
   tmp = [x, y];
-  eval ("gplot tmp");
+  cmd = sprintf ("gplot tmp %s", fmt);
+  eval (cmd);
 
 endfunction
--- a/scripts/plot/__plt__.m
+++ b/scripts/plot/__plt__.m
@@ -16,52 +16,87 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function plot_int (x1, x2)
+function plot_int (caller, ...)
+
+  if (nargin == 2)
+
+    plot_int_1 (va_arg (), "");
+
+  elseif (nargin > 2)
+
+    first_plot = 1;
+    hold_state = ishold;
 
-  if (nargin == 1)
-    [nr, nc] = size (x1);
-    if (nr == 1)
-      x1 = x1';
-      tmp = nr;
-      nr = nc;
-      nc = tmp;
-    endif
-    x1_i = imag (x1);
-    if (any (any (x1_i)))
-      x2 = x1_i;
-      x1 = real (x1);
-    else
-      x2 = x1;
-      x1 = (1:nr)';
-    endif
-  endif
+    unwind_protect
+
+      x = va_arg ();
+      nargin = nargin - 2;
+      x_set = 1;
+      y_set = 0;
+
+# Gather arguments, decode format, and plot lines.
+
+      while (nargin-- > 0)
+
+	fmt = "";
+	new = va_arg ();
 
-  if (nargin <= 2)
-    if (any (any (imag (x1))))
-      x1 = real (x1);
-    endif
-    if (any (any (imag (x2))))
-      x2 = real (x2);
-    endif
-    if (is_scalar (x1))
-      if (is_scalar (x2))
-        plot_2_s_s (x1, x2);
+	if (isstr (new))
+	  if (! x_set)
+	    error ("plot: no data to plot");
+	  endif
+	  fmt = plot_opt (caller, new);
+	  if (! y_set)
+	    plot_int_1 (x, fmt)
+	  else
+	    plot_int_2 (x, y, fmt)
+	  endif
+	  hold on
+	  x_set = 0;
+	  y_set = 0;
+	elseif (x_set)
+	  if (y_set)
+	    plot_int_2 (x, y, fmt);
+	    hold on
+	    x = new;
+	    y_set = 0;
+	  else
+	    y = new;
+	    y_set = 1;          
+	  endif
+	else
+	  x = new;
+	  x_set = 1;
+	endif
+
+      endwhile
+
+# Handle last plot.
+
+      if  (x_set)
+	if (y_set)
+	  plot_int_2 (x, y, fmt);
+	else
+	  plot_int_1 (x, fmt);
+	endif
       endif
-    elseif (is_vector (x1))
-      if (is_vector (x2))
-        plot_2_v_v (x1, x2);
-      elseif (is_matrix (x2))
-        plot_2_v_m (x1, x2);
+
+    unwind_protect_cleanup
+
+      if (! hold_state)
+        hold off
       endif
-    elseif (is_matrix (x1))
-      if (is_vector (x2))
-        plot_2_m_v (x1, x2);
-      elseif (is_matrix (x2))
-        plot_2_m_m (x1, x2);
-      endif
-    endif
+
+    end_unwind_protect
+
   else
-    usage ("plot_int (x [, y])");
+
+    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
--- a/scripts/plot/loglog.m
+++ b/scripts/plot/loglog.m
@@ -16,29 +16,24 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function loglog (x1, x2)
+function loglog (...)
 
 # usage: loglog (x, y)
+#        loglog (x1, y1, x2, y2, ...)
+#        loglog (x, y, fmt)
 #
-# Make a 2D plot of y versus x using log scales for both axes.
+# Make a 2D plot of y versus x using a log scale for the x axis. 
 #
 # See the help message for the plot command for a description of how
 # the arguments are interpreted. 
 #
-# See also: plot, semilogx, semilogy, polar, mesh, contour, bar, stairs,
+# See also: plot, semilogy, loglog, polar, mesh, contour, bar, stairs,
 #           gplot, gsplot, replot, xlabel, ylabel, title 
 
-
   set logscale x;
   set logscale y;
   set nopolar;
 
-  if (nargin == 1)
-    plot_int (x1);
-  elseif (nargin == 2)
-    plot_int (x1, x2);
-  else
-    usage ("loglog (x [, y])");
-  endif
+  plot_int ("loglog", all_va_args);
 
 endfunction
--- a/scripts/plot/plot.m
+++ b/scripts/plot/plot.m
@@ -16,9 +16,11 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function plot (x1, x2)
+function plot (...)
 
 # usage: plot (x, y)
+#        plot (x1, y1, x2, y2, ...)
+#        plot (x, y, fmt)
 #
 # If the first argument is a vector and the second is a matrix, the
 # the vector is plotted versus the columns (or rows) of the matrix.
@@ -42,18 +44,27 @@
 # coordinates and the x coordinates are taken to be the indices of the
 # elements, starting with 1.
 #
-# See also: semilogx, semilogy, loglog, polar, mesh, contour,
+# To see possible options for FMT please see plot_opt.
+#
+# Examples:
+#
+#   plot (x, y, "@12", x, y2, x, y3, "4", x, y4, "+")
+#
+#     y will be plotted with points of type 2 ("+") and color 1 (red).
+#     y2 will be plotted with lines.
+#     y3 will be plotted with lines of color 4.
+#     y4 will be plotted with points which are "+"s.
+#
+#   plot (b, "*")
+#
+#     b will be plotted with points of type "*".
+#
+# See also: semilogx, semilogy, loglog, polar, mesh, contour, plot_opt
 #           bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title 
 
   set nologscale;
   set nopolar;
 
-  if (nargin == 1)
-    plot_int (x1);
-  elseif (nargin == 2)
-    plot_int (x1, x2);
-  else
-    usage ("plot (x [, y])");
-  endif
+  plot_int ("plot", all_va_args);
 
 endfunction
--- a/scripts/plot/polar.m
+++ b/scripts/plot/polar.m
@@ -16,24 +16,40 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function polar (x1, x2)
+function polar (x1, x2, fmt)
 
-# usage: polar (theta, rho)
+# usage: polar (theta, rho, fmt)
 #
 # Make a 2D plot given polar the coordinates theta and rho.
 #
+# The optional third argument specifies the line type.
+#
 # See also: plot, semilogx, semilogy, loglog, mesh, contour, bar,
 #           stairs, gplot, gsplot, replot, xlabel, ylabel, title 
 
   set nologscale;
   set nopolar;
 
-  if (nargin == 1)
-    polar_int (x1);
+  if (nargin == 3)
+    if (isstr (fmt))
+      fmt = plot_opt ("polar", fmt);
+    else
+      error ("polar: third argument must be a string");
+    endif
+    polar_int_2 (x1, x2, fmt);
   elseif (nargin == 2)
-    polar_int (x1, x2);
+    if (isstr (x2))
+      fmt = plot_opt ("polar", x2);
+      polar_int_1 (x1, fmt);
+    else
+      fmt = "";
+      polar_int_2 (x1, x2, fmt);
+    endif
+  elseif (nargin == 1)
+    fmt = "";
+    polar_int_1 (x1, fmt);
   else
-    usage ("polar (x [, y])");
+    usage ("polar (theta, rho, fmt)");
   endif
 
 endfunction
--- a/scripts/plot/semilogx.m
+++ b/scripts/plot/semilogx.m
@@ -16,9 +16,11 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function semilogx (x1, x2)
+function semilogx (...)
 
 # usage: semilogx (x, y)
+#        semilogx (x1, y1, x2, y2, ...)
+#        semilogx (x, y, fmt)
 #
 # Make a 2D plot of y versus x using a log scale for the x axis. 
 #
@@ -32,12 +34,6 @@
   set nologscale y;
   set nopolar;
 
-  if (nargin == 1)
-    plot_int (x1);
-  elseif (nargin == 2)
-    plot_int (x1, x2);
-  else
-    usage ("semilogx (x [, y])");
-  endif
+  plot_int ("semilogx", all_va_args);
 
 endfunction
--- a/scripts/plot/semilogy.m
+++ b/scripts/plot/semilogy.m
@@ -16,11 +16,13 @@
 # along with Octave; see the file COPYING.  If not, write to the Free
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-function semilogy (x1, x2)
+function semilogy (...)
 
 # usage: semilogy (x, y)
+#        semilogy (x1, y1, x2, y2, ...)
+#        semilogy (x, y, fmt)
 #
-# Make a 2D plot of y versus x using a log scale for the y axis. 
+# Make a 2D plot of y versus x using a log scale for the x axis. 
 #
 # See the help message for the plot command for a description of how
 # the arguments are interpreted. 
@@ -32,12 +34,6 @@
   set logscale y;
   set nopolar;
 
-  if (nargin == 1)
-    plot_int (x1);
-  elseif (nargin == 2)
-    plot_int (x1, x2);
-  else
-    usage ("semilogy (x [, y])");
-  endif
+  plot_int ("semilogy", all_va_args);
 
 endfunction