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: Daniel J Sebald
Subject: patch to plot all data at once without "hold on" if possible
Date: Mon, 24 Jan 2005 05:43:34 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020

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 also attached a patch from a few weeks back in case someone wants that.

...

Inside __plt__.m is a variable "first_plot = 1;" What is first_plot? Doesn't look like it is used anywhere.

...

Anyone recall the issue with the comment below?:

-- Function File:  contour (X, Y, Z, N)
    Make a contour plot of the three-dimensional surface described by
    Z.  Someone needs to improve `gnuplot''s contour routines before
    this will be very useful.

What is the problem with gnuplot's contour?

Dan


diff -urP plot-2_1_64/__plt1__.m plot/__plt1__.m
--- plot-2_1_64/__plt1__.m      2004-12-07 19:10:43.000000000 -0600
+++ plot/__plt1__.m     2005-01-24 03:01:36.000000000 -0600
@@ -23,7 +23,7 @@
 
 ## Author: jwe
 
-function __plt1__ (x1, fmt)
+function [varargout] = __plt1__ (x1, fmt)
 
   if (nargin < 1 || nargin > 2)
     usage ("__plt1__ (x1, fmt)");
@@ -53,6 +53,10 @@
     x1 = (1:nr)';
   endif
 
-  __plt2__ (x1, x2, fmt);
+  if (nargout == 2)
+    [varargout{1}, varargout{2}] = __plt2__ (x1, x2, fmt);
+  else
+    __plt2__ (x1, x2, fmt);
+  end
 
 endfunction
diff -urP plot-2_1_64/__plt2__.m plot/__plt2__.m
--- plot-2_1_64/__plt2__.m      2004-12-07 19:10:43.000000000 -0600
+++ plot/__plt2__.m     2005-01-24 05:30:51.073522640 -0600
@@ -23,7 +23,7 @@
 
 ## Author: jwe
 
-function __plt2__ (x1, x2, fmt)
+function [varargout] = __plt2__ (x1, x2, fmt)
 
   if (nargin < 2 || nargin > 3)
     usage ("__plt2__ (x1, x2, fmt)");
@@ -33,6 +33,11 @@
     fmt = "";
   endif
 
+  if (nargout == 2)
+    varargout{1} = [];
+    varargout{2} = [];
+  end
+
   if (! isstr (fmt))
     error ("__plt2__: fmt must be a string");
   endif
@@ -45,11 +50,19 @@
   endif
   if (isscalar (x1))
     if (isscalar (x2))
-      __plt2ss__ (x1, x2, fmt);
+      if (nargout == 2)
+        [varargout{1}, varargout{2}] = __plt2ss__ (x1, x2, fmt);
+      else
+        __plt2ss__ (x1, x2, fmt);
+      end
     endif
   elseif (isvector (x1))
     if (isvector (x2))
-      __plt2vv__ (x1, x2, fmt);
+      if (nargout == 2)
+        [varargout{1}, varargout{2}] = __plt2vv__ (x1, x2, fmt);
+      else
+        __plt2vv__ (x1, x2, fmt);
+      end
     elseif (ismatrix (x2))
       __plt2vm__ (x1, x2, fmt);
     endif
diff -urP plot-2_1_64/__plt2ss__.m plot/__plt2ss__.m
--- plot-2_1_64/__plt2ss__.m    2004-12-07 19:10:43.000000000 -0600
+++ plot/__plt2ss__.m   2005-01-24 02:34:04.000000000 -0600
@@ -23,7 +23,7 @@
 
 ## Author: jwe
 
-function __plt2ss__ (x, y, fmt)
+function [varargout] = __plt2ss__ (x, y, fmt)
 
   if (nargin < 2 || nargin > 3)
     msg = sprintf ("__plt2ss__ (x, y)");
@@ -40,8 +40,13 @@
 
   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);
+    if (nargout == 2)
+      varargout{1} = tmp;
+      varargout{2} = fmt;
+    else
+      cmd = sprintf ("gplot tmp %s", fmt);
+      eval (cmd);
+    end
   else
     error ("__plt2ss__: arguments must be scalars");
   endif
diff -urP plot-2_1_64/__plt2vv__.m plot/__plt2vv__.m
--- plot-2_1_64/__plt2vv__.m    2004-12-07 19:10:43.000000000 -0600
+++ plot/__plt2vv__.m   2005-01-24 02:34:29.000000000 -0600
@@ -23,7 +23,7 @@
 
 ## Author: jwe
 
-function __plt2vv__ (x, y, fmt)
+function [varargout] = __plt2vv__ (x, y, fmt)
 
   if (nargin < 2 || nargin > 3)
     msg = sprintf ("__plt2vv__ (x, y)\n");
@@ -57,7 +57,12 @@
   endif
 
   tmp = [x, y];
-  cmd = sprintf ("gplot tmp %s", fmt);
-  eval (cmd);
+  if (nargout == 2)
+    varargout{1} = tmp;
+    varargout{2} = fmt;
+  else
+    cmd = sprintf ("gplot tmp %s", fmt);
+    eval (cmd);
+  end
 
 endfunction
diff -urP plot-2_1_64/__plt__.m plot/__plt__.m
--- plot-2_1_64/__plt__.m       2004-12-07 19:10:43.000000000 -0600
+++ plot/__plt__.m      2005-01-24 05:29:44.293674720 -0600
@@ -43,31 +43,47 @@
       nargs -= 2;
       x_set = 1;
       y_set = 0;
+      gp_cmd = "gplot";
+      gp_cmd_start_length = length (gp_cmd);
 
-      ## 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 (length(gp_cmd) > gp_cmd_start_length)
+          cmastr = ", \\\n";
+        else
+          cmastr = "";
+        end
+
         if (isstr (new))
           if (! x_set)
             error ("plot: no data to plot");
           endif
           fmt = __pltopt__ (caller, new);
           if (! y_set)
-            __plt1__ (x, fmt);
+            eval (sprintf ("[dat%d gpstr] = __plt1__ (x, fmt);", k));
           else
-            __plt2__ (x, y, fmt);
+            eval (sprintf ("[dat%d gpstr] = __plt2__ (x, y, fmt);", k));
           endif
-          hold on;
+          if isempty (gpstr)
+            hold on; ## Plot done inside function.
+          else
+            gp_cmd = sprintf ("%s%s dat%d %s", gp_cmd, cmastr, k, gpstr);
+          end
           x_set = 0;
           y_set = 0;
         elseif (x_set)
           if (y_set)
-            __plt2__ (x, y, fmt);
-            hold on;
+            eval (sprintf ("[dat%d gpstr] = __plt2__ (x, y, fmt);", k));
+            if isempty (gpstr)
+              hold on; ## Plot done inside function.
+            else
+              gp_cmd = sprintf ("%s%s dat%d %s", gp_cmd, cmastr, k, gpstr);
+            end
             x = new;
             y_set = 0;
           else
@@ -85,12 +101,21 @@
 
       if  (x_set)
         if (y_set)
-          __plt2__ (x, y, fmt);
+          eval (sprintf ("[dat%d gpstr] = __plt2__ (x, y, fmt);", k));
         else
-          __plt1__ (x, fmt);
+          eval (sprintf ("[dat%d gpstr] = __plt1__ (x, fmt);", k));
         endif
+        if isempty (gpstr)
+          hold on; ## Plot done inside function.
+        else
+          gp_cmd = sprintf ("%s%s dat%d %s", gp_cmd, cmastr, k, gpstr);
+        end
       endif
 
+      if (length (gp_cmd) > gp_cmd_start_length)
+        eval (gp_cmd);
+      end
+
     unwind_protect_cleanup
 
       if (! hold_state)
--- __pltopt1__.m.orig  2004-12-07 19:10:43.000000000 -0600
+++ __pltopt1__.m       2005-01-02 22:31:34.488511888 -0600
@@ -101,6 +101,8 @@
       set_linestyle = "dot";
     elseif (strcmp (char, "@"))
       set_points = 1;
+      set_symbol = 1;
+      symbol = "7";
     elseif (strcmp (char, "^"))
       set_impulses = 1;
     elseif (strcmp (char, "L"))
@@ -145,19 +147,19 @@
     elseif (strcmp (char, "*"))
       set_points = 1;
       set_symbol = 1;
-      symbol = "6";
+      symbol = "3";
     elseif (strcmp (char, "+"))
       set_points = 1;
       set_symbol = 1;
-      symbol = "2";
+      symbol = "1";
     elseif (strcmp (char, "o"))
       set_points = 1;
       set_symbol = 1;
-      symbol = "1";
+      symbol = "6";
     elseif (strcmp (char, "x"))
       set_points = 1;
       set_symbol = 1;
-      symbol = "4";
+      symbol = "2";
     elseif (strcmp (char, ";"))  # title mode.
       working = 1;
       while (working)

reply via email to

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