octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch to plot all data at once without "hold on" if possible


From: John W. Eaton
Subject: patch to plot all data at once without "hold on" if possible
Date: Mon, 24 Jan 2005 13:51:14 -0500

On 24-Jan-2005, Daniel J Sebald <address@hidden> wrote:

| I've attached a patch for slight modifications to a variety of 
| __plot###__.m scripts that will allow plot() to be carried out in a 
| single step in most convenient uses.
| 
| The reason I did this is that with gnuplot one can set the output to PDF 
| and put a series of plots in the file then page through using AcroRead 
| or Xpdf.  The problem was that the __plt__.m script used "hold on" for 
| all multiple line and/or symbol plots.  The result in the PDF file was, 
| for example, one page with the symbols and a next page with the symbols 
| and stems.
| 
|  From the original writing of __plt__.m it would have been nice to not 
| use "hold on".  Even in x11 one line is drawn, then the plot ranges 
| readjust upon the plotting of the second line.  Anyhow, the patch would 
| improve things.
| 
| The patch is a very simple workaround that avoids upsetting the apple 
| cart.  I modified __plt1__.m, __plt2__.m, __plt2ss__.m, and __plt2vv__.m 
| to have variable output arguments.  Call all these routines without 
| output arguments, they behave just as previously.  With output 
| arguments, they return the data and the associated format string... 
| EXCEPT in the case of matrices which are done as a loop so format 
| strings are not easily returned.  In the latter case functions return 
| empty matrices and __plt__.m can adjust accordingly.
| 
| __plt__.m will save all the returned data and construct a single gnuplot 
| string for the plots.  The exception is that when matrices are passed 
| into the plot() function.  In that case, the matrix portions utilize the 
| same "hold on" approach.  Hence, if one uses just a string of vectors in 
| the plot command, e.g.,
| 
| plot([1:50], "-r;steep;", [1:50]*2, "-g;steeper;")
| 
| You should see slightly nicer behavior.

I started with your patch and fixed a few more things.  My changes are
below.  I think it is safe to make backwardly-incompatible changes to
the __pltXX__ functions since they were supposed to be "internal"
functions.

This is a change that should have been made a long time ago.

Thanks!

jwe


scripts/ChangeLog:

2005-01-24  John W. Eaton  <address@hidden>

        * plot/__plr2__.m, plot/__plt2__.m: Improve diagnostics.

        * plot/__plr__.m: Use __plt__, not specific __pltXX__ functions.
        * plot/__plt1__.m, plot/__plt2__.m, plot/__plt2mm__.m,
        plot/__plt2mv__.m, plot/__plt2ss__.m, plot/__plt2vm__.m,
        plot/__plt2vv__.m:
        Return data and gnuplot commands instead of evaluating them.
        * plot/__plt__.m: Handle evaluation of all gnuplot commands here.
        Based on changes from Daniel J Sebald <address@hidden>.

Index: scripts/plot/__plr2__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__plr2__.m,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- scripts/plot/__plr2__.m     9 Aug 2002 18:58:14 -0000       1.17
+++ scripts/plot/__plr2__.m     24 Jan 2005 18:38:45 -0000      1.18
@@ -41,12 +41,14 @@
     if (isscalar (rho))
       x = rho * cos (theta);
       y = rho * sin (theta);
-      __plt2ss__ (x, y, fmt);
+      __plt__ (x, y, fmt);
+    else
+      error ("__plr2__: invalid data for plotting");
     endif
   elseif (isvector (theta))
     if (isvector (rho))
       if (length (theta) != length (rho))
-        error ("polar: vector lengths must match");
+        error ("__plr2__: vector lengths must match");
       endif
       if (rows (rho) == 1)
         rho = rho';
@@ -56,7 +58,7 @@
       endif
       x = rho .* cos (theta);
       y = rho .* sin (theta);
-      __plt2vv__ (x, y, fmt);
+      __plt__ (x, y, fmt);
     elseif (ismatrix (rho))
       [t_nr, t_nc] = size (theta);
       if (t_nr == 1)
@@ -73,11 +75,13 @@
         r_nc = tmp;
       endif
       if (t_nr != r_nr)
-        error ("polar: vector and matrix sizes must match");
+        error ("__plr2__: vector and matrix sizes must match");
       endif
       x = diag (cos (theta)) * rho;
       y = diag (sin (theta)) * rho;
-      __plt2vm__ (x, y, fmt);
+      __plt__ (x, y, fmt);
+    else
+      error ("__plr2__: invalid data for plotting")
     endif
   elseif (ismatrix (theta))
     if (isvector (rho))
@@ -96,20 +100,24 @@
         t_nc = tmp;
       endif
       if (r_nr != t_nr)
-        error ("polar: vector and matrix sizes must match");
+        error ("__plr2__: vector and matrix sizes must match");
       endif
       diag_r = diag (rho);
       x = diag_r * cos (theta);
       y = diag_r * sin (theta);
-      __plt2mv__ (x, y, fmt);
+      __plt__ (x, y, fmt);
     elseif (ismatrix (rho))
       if (size (rho) != size (theta))
-        error ("polar: matrix dimensions must match");
+        error ("__plr2__: matrix dimensions must match");
       endif
       x = rho .* cos (theta);
       y = rho .* sin (theta);
-      __plt2mm__ (x, y, fmt);
+      __plt__ (x, y, fmt);
+    else
+      error ("__plr2__: invalid data for plotting")
     endif
+  else
+    error ("__plr2__: invalid data for plotting")
   endif
 
 endfunction
Index: scripts/plot/__plr__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__plr__.m,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- scripts/plot/__plr__.m      9 Aug 2002 18:58:14 -0000       1.17
+++ scripts/plot/__plr__.m      24 Jan 2005 18:38:45 -0000      1.18
@@ -43,6 +43,11 @@
     endif
   endif
 
+  ## Note that we call __plt__ instead of __pltXX__ below, even though
+  ## we know the argument types.  This is so we don't have to duplicate
+  ## the functionality of __plt__ here (the __pltXX__ functions only
+  ## return data and fmtstr now).
+
   if (nargin <= 2)
     if (any (imag (theta)))
       theta = real (theta);
@@ -54,7 +59,7 @@
       if (isscalar (rho))
         x = rho * cos (theta);
         y = rho * sin (theta);
-        __plt2ss__ (x, y, fmt);
+        __plt__ (x, y, fmt);
       endif
     elseif (isvector (theta))
       if (isvector (rho))
@@ -69,7 +74,7 @@
         endif
         x = rho .* cos (theta);
         y = rho .* sin (theta);
-        __plt2vv__ (x, y, fmt);
+        __plt__ (x, y, fmt);
       elseif (ismatrix (rho))
         [t_nr, t_nc] = size (theta);
         if (t_nr == 1)
@@ -90,7 +95,7 @@
         endif
         x = diag (cos (theta)) * rho;
         y = diag (sin (theta)) * rho;
-        __plt2vm__ (x, y, fmt);
+        __plt__ (x, y, fmt);
       endif
     elseif (ismatrix (theta))
       if (isvector (rho))
@@ -114,14 +119,14 @@
         diag_r = diag (r);
         x = diag_r * cos (theta);
         y = diag_r * sin (theta);
-        __plt2mv__ (x, y, fmt);
+        __plt__ (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);
-        __plt2mm__ (x, y, fmt);
+        __plt__ (x, y, fmt);
       endif
     endif
   else
Index: scripts/plot/__plt1__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__plt1__.m,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- scripts/plot/__plt1__.m     18 Jan 2000 04:09:06 -0000      1.12
+++ scripts/plot/__plt1__.m     24 Jan 2005 18:38:45 -0000      1.13
@@ -18,15 +18,15 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt1__ (@var{x1}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt1__ (@var{x1}, @var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt1__ (x1, fmt)
+function [data, fmtstr] = __plt1__ (x1, fmt)
 
-  if (nargin < 1 || nargin > 2)
-    usage ("__plt1__ (x1, fmt)");
+  if (nargin < 1 || nargin > 2 || nargout != 2)
+    usage ("[data, fmtstr] = __plt1__ (x1, fmt)");
   endif
 
   if (nargin == 1)
@@ -53,6 +53,6 @@
     x1 = (1:nr)';
   endif
 
-  __plt2__ (x1, x2, fmt);
+  [data, fmtstr] = __plt2__ (x1, x2, fmt);
 
 endfunction
Index: scripts/plot/__plt2__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__plt2__.m,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- scripts/plot/__plt2__.m     9 Aug 2002 18:58:14 -0000       1.12
+++ scripts/plot/__plt2__.m     24 Jan 2005 18:38:45 -0000      1.13
@@ -18,15 +18,15 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2__ (@var{x1}, @var{x2}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2__ (@var{x1}, @var{x2}, 
@var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2__ (x1, x2, fmt)
+function [data, fmtstr] = __plt2__ (x1, x2, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    usage ("__plt2__ (x1, x2, fmt)");
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2__ (x1, x2, fmt)");
   endif
 
   if (nargin == 2)
@@ -40,25 +40,35 @@
   if (any (any (imag (x1))))
     x1 = real (x1);
   endif
+
   if (any (any (imag (x2))))
     x2 = real (x2);
   endif
+
   if (isscalar (x1))
     if (isscalar (x2))
-      __plt2ss__ (x1, x2, fmt);
+      [data, fmtstr] = __plt2ss__ (x1, x2, fmt);
+    else
+      error ("__plt2__: invalid data for plotting");
     endif
   elseif (isvector (x1))
     if (isvector (x2))
-      __plt2vv__ (x1, x2, fmt);
+      [data, fmtstr] = __plt2vv__ (x1, x2, fmt);
     elseif (ismatrix (x2))
-      __plt2vm__ (x1, x2, fmt);
+      [data, fmtstr] = __plt2vm__ (x1, x2, fmt);
+    else
+      error ("__plt2__: invalid data for plotting");
     endif
   elseif (ismatrix (x1))
     if (isvector (x2))
-      __plt2mv__ (x1, x2, fmt);
+      [data, fmtstr] = __plt2mv__ (x1, x2, fmt);
     elseif (ismatrix (x2))
-      __plt2mm__ (x1, x2, fmt);
+      [data, fmtstr] = __plt2mm__ (x1, x2, fmt);
+    else
+      error ("__plt2__: invalid data for plotting");
     endif
+  else
+    error ("__plt2__: invalid data for plotting");
   endif
 
 endfunction
Index: scripts/plot/__plt2mm__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__plt2mm__.m,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- scripts/plot/__plt2mm__.m   2 Jan 2003 17:59:17 -0000       1.18
+++ scripts/plot/__plt2mm__.m   24 Jan 2005 18:38:45 -0000      1.19
@@ -18,18 +18,16 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2mm__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2mm__ (@var{x}, @var{y}, 
@var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2mm__ (x, y, fmt)
+function [data, fmtstr] = __plt2mm__ (x, y, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    msg = sprintf ("__plt2mm__ (x, y)\n");
-    msg = sprintf ("%s              __plt2mm__ (x, y, fmt)", msg);
-    usage (msg);
-  elseif (nargin == 2 || fmt == "")
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2mm__ (x, y, fmt)");
+  elseif (nargin == 2 || isempty (fmt))
     fmt = " ";  ## Yes, this is intentionally not an empty string!
   endif
 
@@ -40,20 +38,18 @@
   fmt_nr = rows (fmt);
   if (x_nr == y_nr && x_nc == y_nc)
     if (x_nc > 0)
-      tmp = [x, y];
-      cmd = sprintf ("gplot tmp(:,%d:%d:%d) %s", 1, x_nc, x_nc+1,
-                     deblank (fmt (k, :)));
-      if (k < fmt_nr)
-        k++;
+      if (rows (fmt) == 1)
+       fmt = repmat (fmt, x_nc, 1);
       endif
-      for i = 2:x_nc
-        cmd = sprintf ("%s, tmp(:,%d:%d:%d) %s", cmd, i, x_nc, x_nc+i,
-                       deblank (fmt (k, :)));
-        if (k < fmt_nr)
-          k++;
-        endif
+      tmp = [x, y];
+      dtmp = cell (x_nc, 1);
+      ftmp = cell (x_nc, 1);
+      for i = 1:x_nc
+       dtmp{i} = tmp(:,[i,x_nc+i]);
+       ftmp{i} = deblank (fmt(i,:));
       endfor
-      eval (cmd);
+      data = dtmp;
+      fmtstr = ftmp;
     else
       error ("__plt2mm__: arguments must be a matrices");
     endif
Index: scripts/plot/__plt2mv__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__plt2mv__.m,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- scripts/plot/__plt2mv__.m   2 Jan 2003 17:59:17 -0000       1.19
+++ scripts/plot/__plt2mv__.m   24 Jan 2005 18:38:45 -0000      1.20
@@ -18,18 +18,16 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2mv__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2mv__ (@var{x}, @var{y}, 
@var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2mv__ (x, y, fmt)
+function [data, fmtstr] = __plt2mv__ (x, y, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    msg = sprintf ("__plt2mv__ (x, y)\n");
-    msg = sprintf ("%s              __plt2mv__ (x, y, fmt)", msg);
-    usage (msg);
-  elseif (nargin == 2 || fmt == "")
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2mv__ (x, y, fmt)");
+  elseif (nargin == 2 || isempty (fmt))
     fmt = " ";  ## Yes, this is intentionally not an empty string!
   endif
 
@@ -54,23 +52,19 @@
     error ("__plt2mv__: matrix dimensions must match");
   endif
 
-  k = 1;
-  fmt_nr = rows (fmt);
   if (x_nc > 0)
-    tmp = [x, y];
-    cmd = sprintf ("gplot tmp(:,%d:%d:%d) %s", 1, x_nc, x_nc+1,
-                   deblank (fmt (k, :)));
-    if (k < fmt_nr)
-      k++;
+    if (rows (fmt) == 1)
+      fmt = repmat (fmt, x_nc, 1);
     endif
-    for i = 2:x_nc
-      cmd = sprintf ("%s, tmp(:,%d:%d:%d) %s", cmd, i, x_nc-i+1, x_nc+1,
-                     deblank (fmt (k, :)));
-      if (k < fmt_nr)
-        k++;
-      endif
+    tmp = [x, y];
+    dtmp = cell (x_nc, 1);
+    ftmp = cell (x_nc, 1);
+    for i = 1:x_nc
+      dtmp{i} = tmp(:,[i,x_nc+1]);
+      ftmp{i} = deblank (fmt(i,:));
     endfor
-    eval (cmd);
+    data = dtmp;
+    fmtstr = ftmp;
   else
     error ("__plt2mv__: arguments must be a matrices");
   endif
Index: scripts/plot/__plt2ss__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__plt2ss__.m,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- scripts/plot/__plt2ss__.m   2 Jan 2003 17:59:17 -0000       1.17
+++ scripts/plot/__plt2ss__.m   24 Jan 2005 18:38:45 -0000      1.18
@@ -18,17 +18,15 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2ss__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2ss__ (@var{x}, @var{y}, 
@var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2ss__ (x, y, fmt)
+function [data, fmtstr] = __plt2ss__ (x, y, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    msg = sprintf ("__plt2ss__ (x, y)");
-    msg = sprintf ("%s              __plt2ss__ (x, y, fmt)", msg);
-    usage (msg);
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2ss__ (x, y, fmt)");
   elseif (nargin == 2)
     fmt = "";
   elseif (rows (fmt) > 1)
@@ -40,8 +38,8 @@
 
   if (x_nr == 1 && x_nr == y_nr && x_nc == 1 && x_nc == y_nc)
     tmp = [x, y];
-    cmd = sprintf ("gplot tmp %s", fmt);
-    eval (cmd);
+    data = tmp;
+    fmtstr = fmt;
   else
     error ("__plt2ss__: arguments must be scalars");
   endif
Index: scripts/plot/__plt2vm__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__plt2vm__.m,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- scripts/plot/__plt2vm__.m   9 Nov 2004 05:53:11 -0000       1.20
+++ scripts/plot/__plt2vm__.m   24 Jan 2005 18:38:45 -0000      1.21
@@ -18,18 +18,16 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2vm__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2vm__ (@var{x}, @var{y}, 
@var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2vm__ (x, y, fmt)
+function [data, fmtstr] = __plt2vm__ (x, y, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    msg = sprintf ("__plt2vm__ (x, y)\n");
-    msg = sprintf ("%s              __plt2vm__ (x, y, fmt)", msg);
-    usage (msg);
-  elseif (nargin == 2 || fmt == "")
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2vm__ (x, y, fmt)");
+  elseif (nargin == 2 || isempty (fmt))
     fmt = " ";  ## Yes, this is intentionally not an empty string!
   endif
 
@@ -54,23 +52,19 @@
     error ("__plt2vm__: matrix dimensions must match");
   endif
 
-  k = 1;
-  fmt_nr = rows (fmt);
   if (y_nc > 0)
-    tmp = [x, y];
-    cmd = sprintf ("gplot tmp(:,%d:%d:%d) %s", 1, x_nc, x_nc+1,
-                   deblank (fmt (k, :)));
-    if (k < fmt_nr)
-      k++;
+    if (rows (fmt) == 1)
+      fmt = repmat (fmt, y_nc, 1);
     endif
-    for i = 2:y_nc
-      cmd = sprintf ("%s, tmp(:,%d:%d:%d) %s", cmd, 1, i, i+1,
-                     deblank (fmt (k, :)));
-      if (k < fmt_nr)
-        k++;
-      endif
+    tmp = [x, y];
+    dtmp = cell (y_nc, 1);
+    ftmp = cell (y_nc, 1);
+    for i = 1:y_nc
+      dtmp{i} = tmp(:,[1,i+1]);
+      ftmp{i} = deblank (fmt(i,:));
     endfor
-    eval (cmd);
+    data = dtmp;
+    fmtstr = ftmp;
   else
     error ("__plt2vm__: arguments must be a matrices");
   endif
Index: scripts/plot/__plt2vv__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__plt2vv__.m,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- scripts/plot/__plt2vv__.m   2 Jan 2003 17:59:17 -0000       1.17
+++ scripts/plot/__plt2vv__.m   24 Jan 2005 18:38:45 -0000      1.18
@@ -18,17 +18,15 @@
 ## 02111-1307, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2vv__ (@var{x}, @var{y}, @var{fmt})
+## @deftypefn {Function File} {[data, fmtstr] =} __plt2vv__ (@var{x}, @var{y}, 
@var{fmt})
 ## @end deftypefn
 
 ## Author: jwe
 
-function __plt2vv__ (x, y, fmt)
+function [data, fmtstr] = __plt2vv__ (x, y, fmt)
 
-  if (nargin < 2 || nargin > 3)
-    msg = sprintf ("__plt2vv__ (x, y)\n");
-    msg = sprintf ("%s              __plt2vv__ (x, y, fmt)", msg);
-    usage (msg);
+  if (nargin < 2 || nargin > 3 || nargout != 2)
+    usage ("[data, fmtstr] = __plt2vv__ (x, y, fmt)");
   elseif (nargin == 2)
     fmt = "";
   elseif (rows (fmt) > 1)
@@ -56,8 +54,7 @@
     error ("__plt2vv__: vector lengths must match");
   endif
 
-  tmp = [x, y];
-  cmd = sprintf ("gplot tmp %s", fmt);
-  eval (cmd);
+  data = [x, y];
+  fmtstr = fmt;
 
 endfunction
Index: scripts/plot/__plt__.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/plot/__plt__.m,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- scripts/plot/__plt__.m      23 Jan 2004 03:15:53 -0000      1.24
+++ scripts/plot/__plt__.m      24 Jan 2005 18:38:45 -0000      1.25
@@ -27,11 +27,7 @@
 
   nargs = nargin ();
 
-  if (nargs == 2)
-
-    __plt1__ (varargin{1}, "");
-
-  elseif (nargs > 2)
+  if (nargs >= 2)
 
     first_plot = 1;
     hold_state = ishold ();
@@ -39,35 +35,64 @@
     unwind_protect
 
       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, and plot lines.
+      ## Gather arguments, decode format, gather plot strings, and plot lines.
 
       while (nargs-- > 0)
 
         fmt = "";
         new = varargin{k++};
 
+        if (j > 1)
+          sep = ",\\\n";
+        else
+          sep = "";
+        endif
+
         if (isstr (new))
           if (! x_set)
             error ("plot: no data to plot");
           endif
           fmt = __pltopt__ (caller, new);
           if (! y_set)
-            __plt1__ (x, fmt);
+            [data{j}, fmtstr] = __plt1__ (x, fmt);
           else
-            __plt2__ (x, y, fmt);
+            [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
-          hold on;
           x_set = 0;
           y_set = 0;
         elseif (x_set)
           if (y_set)
-            __plt2__ (x, y, fmt);
-            hold on;
+            [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
@@ -83,14 +108,29 @@
 
       ## Handle last plot.
 
-      if  (x_set)
+      if (x_set)
         if (y_set)
-          __plt2__ (x, y, fmt);
+          [data{j}, fmtstr] = __plt2__ (x, y, fmt);
         else
-          __plt1__ (x, fmt);
+          [data{j}, fmtstr] = __plt1__ (x, 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
       endif
 
+      if (have_gp_cmd)
+        eval (gp_cmd);
+      endif
+
     unwind_protect_cleanup
 
       if (! hold_state)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]