changeset 5493:b2e882e8b68b

[project @ 2005-10-13 17:51:19 by jwe]
author jwe
date Thu, 13 Oct 2005 17:51:19 +0000
parents 179096e8e57f
children 73a87a677257
files scripts/ChangeLog scripts/plot/__axis_label__.m scripts/plot/__errplot__.m scripts/plot/__plot_globals__.m scripts/plot/__plt__.m scripts/plot/__setup_plot__.m scripts/plot/axis.m scripts/plot/grid.m scripts/plot/plot_border.m scripts/plot/replot.m scripts/plot/shg.m scripts/plot/subplot.m scripts/plot/title.m scripts/plot/top_title.m
diffstat 14 files changed, 136 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,23 @@
+2005-10-13  John W. Eaton  <jwe@octave.org>
+
+	* plot/__plt__.m, plot/__errplot__.m, plot/replot.m:
+	If in multiplot mode, clear plot before issuing new plot command.
+
+	* plot/__setup_plot__.m: New function.
+	* plot/__plt__.m, plot__errplot__.m: Use it.
+	Handle multiplot data and offsets here.
+
+	* plot/__plot_globals__.m: Also keep track of multiplot options.
+	Move initialization to __setup_plot__.m.
+
+	* plot/subplot.m: Multiplot globals now in __plot_globals__.m.
+	Don't reset gnuplot_command_replot.
+
+	* plot/replot.m: Handle multiplot data and offsets here.
+	* plot__axis_label__.m, plot/axis.m, plot/grid.m,
+	plot/plot_border.m, plot/plot.m, plot/plot_title.m,
+	plot/top_title.m: Call replot, not __gnuplot_replot__.
+
 2005-10-12  John W. Eaton  <jwe@octave.org>
 
 	* plot/figure.m: Handle __current_figure__, not gnuplot details.
--- a/scripts/plot/__axis_label__.m
+++ b/scripts/plot/__axis_label__.m
@@ -33,8 +33,7 @@
       __gnuplot_raw__ (sprintf ("set %s \"%s\";\n", caller,
 				undo_string_escapes (text)));
       if (automatic_replot)
-	## No semicolon (see replot.m).
-	__gnuplot_replot__
+	replot ();
       endif
     else
       error ("%s: text must be a string", caller);
--- a/scripts/plot/__errplot__.m
+++ b/scripts/plot/__errplot__.m
@@ -38,11 +38,13 @@
 
   __plot_globals__;
 
+  __setup_plot__;
+
   if (nargin < 3 || nargin > 7) # at least three data arguments needed
     usage ("__errplot__ (fmt, arg1, ...)");
   endif
 
-  j = __plot_data_offset__(__current_figure__);
+  j = __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__);
 
   fmt = __pltopt__ ("__errplot__", fstr);
 
@@ -72,11 +74,11 @@
 	       a2(:,i)-a5(:,i), a2(:,i)+a6(:,i)];
     endswitch
 
-    __plot_data__{__current_figure__}{j} = tmp;
+    __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j} = tmp;
 
-    __plot_command__{__current_figure__} \
-	= sprintf ("%s%s __plot_data__{__current_figure__}{%d} %s",
-		   __plot_command__{__current_figure__},
+    __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} \
+	= sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{%d} %s",
+		   __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__},
 		   __plot_command_sep__, j, ifmt);
     __plot_command_sep__ = ",\\\n";
 
@@ -84,10 +86,13 @@
 
   endfor
 
-  __plot_data_offset__(__current_figure__) = j;
+  __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = j;
 
-  if (! isempty (__plot_command__{__current_figure__}))
-    eval (__plot_command__{__current_figure__});
+  if (! isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}))
+      if (__multiplot_mode__)
+	__gnuplot_raw__ ("clear\n");
+      endif
+    eval (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__});
   endif
 
 endfunction
--- a/scripts/plot/__plot_globals__.m
+++ b/scripts/plot/__plot_globals__.m
@@ -19,6 +19,29 @@
 
 ## This is a script file shared by __plt__ and __errplot__.
 
+## global variables to keep track of multiplot options
+
+global __multiplot_mode__ = 0;
+global __multiplot_xsize__;
+global __multiplot_ysize__;
+global __multiplot_xn__;
+global __multiplot_yn__;
+global __multiplot_xi__;
+global __multiplot_yi__;
+global __multiplot_scale__;
+
+if (isempty (__multiplot_scale__))
+  __multiplot_scale__ = [1, 1];
+endif
+
+if (isempty (__multiplot_xi__))
+  __multiplot_xi__ = 1;
+endif
+
+if (isempty (__multiplot_yi__))
+  __multiplot_yi__ = 1;
+endif
+
 global __current_figure__;
 global __plot_data_offset__;
 global __plot_command__;
@@ -29,29 +52,18 @@
   __current_figure__ = 1;
 endif
 
-if (length (__plot_data_offset__) < __current_figure__)
-  __plot_data_offset__(__current_figure__) = 1;
-endif
+if (length (__plot_data_offset__) < __current_figure__
+    || any (size (__plot_data_offset__{__current_figure__}) != [__multiplot_xi__, __multiplot_yi__]))
 
-if (length (__plot_command__) < __current_figure__)
-  __plot_command__{__current_figure__} = "";
-endif
-
-if (length (__plot_data__) < __current_figure__)
-  __plot_data__{__current_figure__} = [];
+  __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = 1;
 endif
 
-if (ishold ())
-  if (isempty (__plot_command__{__current_figure__}))
-    __plot_command__{__current_figure__} = "__gnuplot_plot__";
-    __plot_command_sep__ = "";
-  else
-    gp_cmd = __plot_command__{__current_figure__};
-    __plot_command_sep__ = ",\\\n";
-  endif
-else
-  __plot_command__{__current_figure__} = "__gnuplot_plot__";
-  __plot_command_sep__ = "";
-  __plot_data__{__current_figure__} = [];
-  __plot_data_offset__(__current_figure__) = 1;
+if (length (__plot_command__) < __current_figure__
+    || any (size (__plot_command__{__current_figure__}) != [__multiplot_xi__, __multiplot_yi__]))
+  __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = "";
 endif
+
+if (length (__plot_data__) < __current_figure__
+    || any (size (__plot_data__{__current_figure__}) != [__multiplot_xi__, __multiplot_yi__]))
+  __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = [];
+endif
--- a/scripts/plot/__plt__.m
+++ b/scripts/plot/__plt__.m
@@ -27,12 +27,14 @@
 
   __plot_globals__;
 
+  __setup_plot__;
+
   nargs = nargin ();
 
   if (nargs > 1)
 
     k = 1;
-    j = __plot_data_offset__(__current_figure__);
+    j = __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__);
 
     x_set = false;
     y_set = false;
@@ -54,9 +56,9 @@
 	if (x_set)
 	  fmt = __pltopt__ (caller, next_arg);
 	  if (y_set)
-	    [__plot_data__{__current_figure__}{j}, fmtstr] = __plt2__ (x, y, fmt);
+	    [__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}, fmtstr] = __plt2__ (x, y, fmt);
 	  else
-	    [__plot_data__{__current_figure__}{j}, fmtstr] = __plt1__ (x, fmt);
+	    [__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}, fmtstr] = __plt1__ (x, fmt);
 	  endif
 	  have_data = true;
 	  x_set = false;
@@ -67,7 +69,7 @@
       elseif (x_set)
 	if (y_set)
 	  fmt = __pltopt__ (caller, "");
-	  [__plot_data__{__current_figure__}{j}, fmtstr] = __plt2__ (x, y, fmt);
+	  [__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}, fmtstr] = __plt2__ (x, y, fmt);
 	  have_data = true;
 	  x = next_arg;
 	  y_set = false;
@@ -81,18 +83,18 @@
       endif
 
       if (have_data)
-	if (iscell (__plot_data__{__current_figure__}{j}))
-	  for i = 1:length (__plot_data__{__current_figure__}{j})
-	    __plot_command__{__current_figure__} \
-		= sprintf ("%s%s __plot_data__{__current_figure__}{%d}{%d} %s",
-			   __plot_command__{__current_figure__},
+	if (iscell (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}))
+	  for i = 1:length (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j})
+	    __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} \
+		= sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{%d}{%d} %s",
+			   __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__},
 			   __plot_command_sep__, j, i, fmtstr{i});
 	    __plot_command_sep__ = ",\\\n";
 	  endfor
 	else
-	  __plot_command__{__current_figure__} \
-	    = sprintf ("%s%s __plot_data__{__current_figure__}{%d} %s",
-		       __plot_command__{__current_figure__},
+	  __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} \
+	    = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{%d} %s",
+		       __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__},
 		       __plot_command_sep__, j, fmtstr);
 	  __plot_command_sep__ = ",\\\n";
 	endif
@@ -101,10 +103,13 @@
 
     endwhile
 
-    __plot_data_offset__(__current_figure__) = j;
+    __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = j;
 
-    if (! isempty (__plot_command__{__current_figure__}))
-      eval (__plot_command__{__current_figure__});
+    if (! isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}))
+      if (__multiplot_mode__)
+	__gnuplot_raw__ ("clear\n");
+      endif
+      eval (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__});
     endif
 
   else
new file mode 100644
--- /dev/null
+++ b/scripts/plot/__setup_plot__.m
@@ -0,0 +1,32 @@
+## Copyright (C) 2005 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+## 02110-1301, USA.
+
+if (ishold ())
+  if (isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}))
+    __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = "__gnuplot_plot__";
+    __plot_command_sep__ = "";
+  else
+    __plot_command_sep__ = ",\\\n";
+  endif
+else
+  __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = "__gnuplot_plot__";
+  __plot_command_sep__ = "";
+  __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = [];
+  __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = 1;
+endif
--- a/scripts/plot/axis.m
+++ b/scripts/plot/axis.m
@@ -170,7 +170,7 @@
       __gnuplot_raw__ ("set zrange [] writeback;\n");
       ## XXX FIXME XXX if writeback were set in plot, no need to replot here.
       ## No semicolon (see replot.m).
-      __gnuplot_replot__
+      replot ();
       __gnuplot_raw__ ("set noautoscale x;\n");
       __gnuplot_raw__ ("set noautoscale y;\n");
       __gnuplot_raw__ ("set noautoscale z;\n");
@@ -265,8 +265,7 @@
   if (nargin > 1)
     axis (varargin{:});
   elseif (automatic_replot)
-    ## No semicolon (see replot.m).
-    __gnuplot_replot__
+    replot ();
   endif
 endfunction
 
--- a/scripts/plot/grid.m
+++ b/scripts/plot/grid.m
@@ -59,8 +59,7 @@
   endif
 
   if (do_replot && automatic_replot)
-    ## No semicolon (see replot.m).
-    __gnuplot_replot__
+    replot ();
   endif
 
 endfunction
--- a/scripts/plot/plot_border.m
+++ b/scripts/plot/plot_border.m
@@ -111,8 +111,7 @@
   endif
 
   if (automatic_replot)
-    ## No semicolon (see replot.m).
-    __gnuplot_replot__
+    replot ();
   endif
 
 endfunction
--- a/scripts/plot/replot.m
+++ b/scripts/plot/replot.m
@@ -26,10 +26,15 @@
 
 function replot ()
 
+  __plot_globals__;
+
   if (nargin == 0)
-    ## No semicolon following the __gnuplot_replot__ line unless you
-    ## also fix gplot.l to allow it.
-    __gnuplot_replot__
+    if (! isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}))
+      if (__multiplot_mode__)
+	__gnuplot_raw__ ("clear\n");
+      endif
+      eval (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__});
+    endif
   else
     usage ("replot ()");
   endif
--- a/scripts/plot/shg.m
+++ b/scripts/plot/shg.m
@@ -36,6 +36,6 @@
     warning ("shg: ignoring extra arguments");
   endif
 
-  __gnuplot_replot__ 
+  replot ();
 
 endfunction
--- a/scripts/plot/subplot.m
+++ b/scripts/plot/subplot.m
@@ -82,20 +82,7 @@
 
 function subplot (rows, columns, index)
 
-  ## global variables to keep track of multiplot options
-
-  global __multiplot_mode__ = 0;
-  global __multiplot_xsize__;
-  global __multiplot_ysize__;
-  global __multiplot_xn__;
-  global __multiplot_yn__;
-  global __multiplot_xi__;
-  global __multiplot_yi__;
-  global __multiplot_scale__;
-
-  if (isempty (__multiplot_scale__))
-    __multiplot_scale__ = [1, 1];
-  endif
+  __plot_globals__;
 
   if (nargin != 3 && nargin != 1)
     usage ("subplot (rows, columns, index) or subplot (rcn)");
@@ -155,8 +142,6 @@
       __multiplot_xsize__ = __multiplot_scale__(1) ./ columns;
       __multiplot_ysize__ = __multiplot_scale__(2) ./ rows;
 
-      gnuplot_command_replot = "cle;rep";
-
       __gnuplot_raw__ ("set multiplot;\n");
 
       __gnuplot_raw__ (sprintf ("set size %g, %g;\n",
--- a/scripts/plot/title.m
+++ b/scripts/plot/title.m
@@ -37,8 +37,7 @@
     __gnuplot_raw__ (sprintf ("set title \"%s\";\n",
 			      undo_string_escapes (text)));
     if (automatic_replot)
-      ## No semicolon (see replot.m).
-      __gnuplot_replot__
+      replot ();
     endif
   else
     error ("title: text must be a string");
--- a/scripts/plot/top_title.m
+++ b/scripts/plot/top_title.m
@@ -39,8 +39,7 @@
     __gnuplot_raw__ (sprintf ("set top_title \"%s\";\n",
 			      undo_string_escapes (text)));
     if (automatic_replot)
-      ## No semicolon (see replot.m).
-      __gnuplot_replot__
+      replot ();
     endif
   else
     error ("error: top_title: text must be a string");