changeset 6178:830235f4984f

[project @ 2006-11-17 00:16:57 by jwe]
author jwe
date Fri, 17 Nov 2006 00:19:18 +0000
parents 6ac0c826459e
children 235a1b456cf4
files doc/ChangeLog doc/interpreter/sparseimages.m scripts/ChangeLog scripts/plot/__plot_globals__.m scripts/plot/__render_plot1__.m scripts/plot/__render_plot__.m scripts/plot/print.m scripts/plot/subplot.m
diffstat 8 files changed, 235 insertions(+), 181 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Thu Nov 16 18:49:38 2006 +0000
+++ b/doc/ChangeLog	Fri Nov 17 00:19:18 2006 +0000
@@ -1,3 +1,7 @@
+2006-11-16  John W. Eaton  <jwe@octave.org>
+
+	* interpreter/sparseimages.m (femimages): Use plot3.
+
 2006-11-11  John W. Eaton  <jwe@octave.org>
 
 	* interpreter/Makefile.in (%.texi : %.txi):
--- a/doc/interpreter/sparseimages.m	Thu Nov 16 18:49:38 2006 +0000
+++ b/doc/interpreter/sparseimages.m	Fri Nov 17 00:19:18 2006 +0000
@@ -208,18 +208,11 @@
     velems = reshape( V(elemx), 4, E);
 
     sz = size(xelems,2);
-    ## FIXME How can I do this without a gnuplot specific commands? plot3 anyone?
-    unwind_protect
-      __gnuplot_set__  parametric;
-      __gnuplot_raw__ ("set nohidden3d;\n");
-      tmp = [([xelems; NaN*ones(1,sz)])(:), ([yelems; NaN*ones(1,sz)])(:), ([velems; NaN*ones(1,sz)])(:)];
-      __gnuplot_splot__(tmp);
-      __gnuplot_raw__ ("set view 80,10;\n")
-      print(strcat(nm,".",typ),strcat("-d",typ))
-      bury_output ();
-    unwind_protect_cleanup
-      __gnuplot_set__ noparametric; 
-    end_unwind_protect
+
+    __gnuplot_raw__ ("set view 80,10;\n")
+    plot3 (xelems, yelems, velems);
+    print(strcat(nm,".",typ),strcat("-d",typ))
+    bury_output ();
   endif
 endfunction
 
--- a/scripts/ChangeLog	Thu Nov 16 18:49:38 2006 +0000
+++ b/scripts/ChangeLog	Fri Nov 17 00:19:18 2006 +0000
@@ -1,3 +1,10 @@
+2006-11-16  John W. Eaton  <jwe@octave.org>
+
+	* plot/__render_plot1__.m: New file.
+	* plot/__render_plot__.m: Use it.  Loop over multiplots.
+	* plot/print.m, plot/subplot.m: Don't send "set multiplot" to
+	gnuplot.  Let __render_plot__ do that.
+
 2006-11-16  Francesco Potorti`  <Potorti@isti.cnr.it>
 
 	* plot/plot.m: Fix doc string.
--- a/scripts/plot/__plot_globals__.m	Thu Nov 16 18:49:38 2006 +0000
+++ b/scripts/plot/__plot_globals__.m	Fri Nov 17 00:19:18 2006 +0000
@@ -70,57 +70,57 @@
 endif
 
 if (length (__plot_data_offset__) < __current_figure__
-    || any (size (__plot_data_offset__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
+    || any (size (__plot_data_offset__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
 
-  __plot_data_offset__{__current_figure__}(__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)) = 1;
+  __plot_data_offset__{__current_figure__}(__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)) = 1;
 endif
 
 if (length (__plot_data__) < __current_figure__
-    || any (size (__plot_data__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
-  __plot_data__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = [];
+    || any (size (__plot_data__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
+  __plot_data__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
 endif
 
 if (length (__plot_data_type__) < __current_figure__
-    || any (size (__plot_data_type__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
-  __plot_data_type__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = [];
+    || any (size (__plot_data_type__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
+  __plot_data_type__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
 endif
 
 if (length (__plot_data_parametric__) < __current_figure__
-    || any (size (__plot_data_parametric__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
-  __plot_data_parametric__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = [];
+    || any (size (__plot_data_parametric__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
+  __plot_data_parametric__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
 endif
 
 if (length (__plot_image_colormap__) < __current_figure__
-    || any (size (__plot_image_colormap__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
-  __plot_image_colormap__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = [];
+    || any (size (__plot_image_colormap__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
+  __plot_image_colormap__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
 endif
 
 if (length (__plot_image_dims__) < __current_figure__
-    || any (size (__plot_image_dims__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
-  __plot_image_dims__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = [];
+    || any (size (__plot_image_dims__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
+  __plot_image_dims__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
 endif
 
 if (length (__plot_fmtstr__) < __current_figure__
-    || any (size (__plot_fmtstr__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
-  __plot_fmtstr__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = [];
+    || any (size (__plot_fmtstr__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
+  __plot_fmtstr__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
 endif
 
 if (length (__plot_usingstr__) < __current_figure__
-    || any (size (__plot_usingstr__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
-  __plot_usingstr__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = [];
+    || any (size (__plot_usingstr__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
+  __plot_usingstr__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
 endif
 
 if (length (__plot_withstr__) < __current_figure__
-    || any (size (__plot_withstr__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
-  __plot_withstr__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = [];
+    || any (size (__plot_withstr__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
+  __plot_withstr__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
 endif
 
 if (length (__plot_key_labels__) < __current_figure__
-    || any (size (__plot_key_labels__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
-  __plot_key_labels__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = [];
+    || any (size (__plot_key_labels__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
+  __plot_key_labels__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yn__(__current_figure__)} = [];
 endif
 
 if (length (__plot_key_properties__) < __current_figure__
-    || any (size (__plot_key_properties__{__current_figure__}) != [__multiplot_xi__(__current_figure__), __multiplot_yi__(__current_figure__)]))
-  __plot_key_properties__{__current_figure__}{__multiplot_xi__(__current_figure__),__multiplot_yi__(__current_figure__)} = struct ("visible", true, "box", false, "position", 0);
+    || any (size (__plot_key_properties__{__current_figure__}) != [__multiplot_xn__(__current_figure__), __multiplot_yn__(__current_figure__)]))
+  __plot_key_properties__{__current_figure__}{__multiplot_xn__(__current_figure__),__multiplot_yi__(__current_figure__)} = struct ("visible", true, "box", false, "position", 0);
 endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/__render_plot1__.m	Fri Nov 17 00:19:18 2006 +0000
@@ -0,0 +1,153 @@
+## Copyright (C) 2006 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.
+
+function __render_plot1__ (mxi, myi)
+
+  __plot_globals__;
+
+  cf = __current_figure__;
+
+  if (! isempty (__plot_data__{cf}{mxi,myi}))
+
+    have_image = false;
+
+    for j = 1:length (__plot_data__{cf}{mxi,myi})
+      if (__plot_data_type__{cf}{mxi,myi}(j) == 1)
+	have_image = true;
+      endif
+      ## Do this check before sending any commands to gnuplot so that if
+      ## there is an error, we don't leave things in a bad state.
+      if (j == 1)
+	first_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
+	this_plot_data_type = first_plot_data_type;
+      else
+	this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
+	if ((first_plot_data_type != 3 && this_plot_data_type == 3)
+	    || (first_plot_data_type == 3 && this_plot_data_type != 3))
+	  error ("can't mix 2-d and 3-d data in the same plot");
+	endif
+      endif
+    endfor
+
+    if (have_image)
+      __gnuplot_raw__ ("set size ratio -1;\n");
+
+      cmap = __plot_image_colormap__{cf}{mxi,myi};
+
+      palette_size = rows (cmap);
+      __gnuplot_raw__ (sprintf ("set palette positive color model RGB maxcolors %i\n",
+				palette_size));
+
+      __gnuplot_raw__ ("set palette file \"-\"\n");
+      tmp = round (1000 * cmap) / 1000;
+      tmp_rows = rows (tmp);
+      idx = (0:tmp_rows-1)';
+      __gnuplot_raw__ (sprintf ("%d %.4g %.4g %.4g\n", [idx, tmp]'));
+      __gnuplot_raw__("e\n");
+
+      __gnuplot_raw__ ("set autoscale fix\n"); # "fix" is helpful for "a" hotkey
+      __gnuplot_raw__ ("set tics out\n");
+    endif
+
+    first = true;
+
+    for j = 1:length (__plot_data__{cf}{mxi,myi})
+
+      this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
+
+      for i = 1:length (__plot_data__{cf}{mxi,myi}{j})
+
+	if (first)
+	  first = false;
+	  __do_legend__ ();
+	  if (first_plot_data_type == 3)
+	    cmd = gnuplot_command_splot;
+	  else
+	    cmd = gnuplot_command_plot;
+	  endif
+	  __gnuplot_raw__ (sprintf ("%s ", cmd));
+	else
+	  __gnuplot_raw__ (",\\\n");
+	endif
+
+	if (this_plot_data_type == 1)
+	  label = undo_string_escapes (__plot_key_labels__{cf}{mxi,myi}{j}{i});
+
+	  tmp = __plot_image_dims__{cf}{mxi,myi}{j}{i};
+
+	  x_dim = tmp(1);
+	  y_dim = tmp(2);
+	  x_origin = tmp(3);
+	  y_origin = tmp(4);
+	  dx = tmp(5);
+	  dy = tmp(6);
+
+	  A = __plot_data__{cf}{mxi,myi}{j}{i};
+
+	  ## Let the file be deleted when Octave exits or
+	  ## `purge_tmp_files' is called.
+	  [fid, binary_file_name, msg] ...
+	      = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1);
+
+	  ## Gnuplot reads binary files very quickly.  However, the
+	  ## 'fwrite' below is much slower than using the current
+	  ## '__gnuplot_plot__' command.
+	  fwrite (fid, A(:), "float");
+	  fclose (fid);
+
+	  __gnuplot_raw__ (sprintf ("\"%s\" binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using 1 %s '%s' with image",
+				    binary_file_name, x_dim, y_dim, x_origin,
+				    y_origin, dx, dy,
+				    gnuplot_command_title, label));
+	else
+	  usingstr = __plot_usingstr__{cf}{mxi,myi}{j}{i};
+	  fmtstr = __plot_fmtstr__{cf}{mxi,myi}{j}{i};
+	  withstr = __plot_withstr__{cf}{mxi,myi}{j}{i};
+
+	  label = undo_string_escapes (__plot_key_labels__{cf}{mxi,myi}{j}{i});
+
+	  __gnuplot_raw__ (sprintf ("'-' %s %s '%s' %s %s %s", usingstr,
+				    gnuplot_command_title, label, fmtstr,
+				    withstr));
+	endif
+      endfor
+    endfor
+
+    for j = 1:length (__plot_data__{cf}{mxi,myi})
+      for i = 1:length (__plot_data__{cf}{mxi,myi}{j})
+	this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
+	if (this_plot_data_type != 1)
+	  if (this_plot_data_type == 3)
+	    parametric = __plot_data_parametric__{cf}{mxi,myi}{j}{i};
+	  else
+	    parametric = false;
+	  endif
+	  __gnuplot_send_inline_data__ (__plot_data__{cf}{mxi,myi}{j}{i},
+					this_plot_data_type, parametric);
+	endif
+      endfor
+    endfor
+
+    if (! first)
+      __gnuplot_raw__ ("\n");
+    endif
+
+  endif
+
+endfunction
--- a/scripts/plot/__render_plot__.m	Thu Nov 16 18:49:38 2006 +0000
+++ b/scripts/plot/__render_plot__.m	Fri Nov 17 00:19:18 2006 +0000
@@ -22,138 +22,34 @@
   __plot_globals__;
 
   cf = __current_figure__;
-  mxi = __multiplot_xi__(cf);
-  myi = __multiplot_yi__(cf);
-
-  if (! isempty (__plot_data__{cf}{mxi,myi}))
-
-    have_image = false;
-
-    for j = 1:length (__plot_data__{cf}{mxi,myi})
-      if (__plot_data_type__{cf}{mxi,myi}(j) == 1)
-	have_image = true;
-      endif
-      ## Do this check before sending any commands to gnuplot so that if
-      ## there is an error, we don't leave things in a bad state.
-      if (j == 1)
-	first_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
-	this_plot_data_type = first_plot_data_type;
-      else
-	this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
-	if ((first_plot_data_type != 3 && this_plot_data_type == 3)
-	    || (first_plot_data_type == 3 && this_plot_data_type != 3))
-	  error ("can't mix 2-d and 3-d data in the same plot");
-	endif
-      endif
-    endfor
+  mxn = __multiplot_xn__(cf);
+  myn = __multiplot_yn__(cf);
 
-    if (__multiplot_mode__(cf))
-      __gnuplot_raw__ ("clear\n");
-    endif
-
-    if (have_image)
-      __gnuplot_raw__ ("set size ratio -1;\n");
-
-      cmap = __plot_image_colormap__{cf}{mxi,myi};
-
-      palette_size = rows (cmap);
-      __gnuplot_raw__ (sprintf ("set palette positive color model RGB maxcolors %i\n",
-				palette_size));
-
-      __gnuplot_raw__ ("set palette file \"-\"\n");
-      tmp = round (1000 * cmap) / 1000;
-      tmp_rows = rows (tmp);
-      idx = (0:tmp_rows-1)';
-      __gnuplot_raw__ (sprintf ("%d %.4g %.4g %.4g\n", [idx, tmp]'));
-      __gnuplot_raw__("e\n");
-
-      __gnuplot_raw__ ("set autoscale fix\n"); # "fix" is helpful for "a" hotkey
-      __gnuplot_raw__ ("set tics out\n");
-    endif
-
-    first = true;
-
-    for j = 1:length (__plot_data__{cf}{mxi,myi})
-
-      this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
+  if (__multiplot_mode__(cf))
+    __gnuplot_raw__ ("set size 1, 1;\n");
+    __gnuplot_raw__ ("set origin 0, 0;\n");
+    __gnuplot_raw__ ("set multiplot;\n");
+    for mxi = 1:mxn
+      for myi = 1:myn
 
-      for i = 1:length (__plot_data__{cf}{mxi,myi}{j})
-
-	if (first)
-	  first = false;
-	  __do_legend__ ();
-	  if (first_plot_data_type == 3)
-	    cmd = gnuplot_command_splot;
-	  else
-	    cmd = gnuplot_command_plot;
-	  endif
-	  __gnuplot_raw__ (sprintf ("%s ", cmd));
-	else
-	  __gnuplot_raw__ (",\\\n");
-	endif
-
-	if (this_plot_data_type == 1)
-	  label = undo_string_escapes (__plot_key_labels__{cf}{mxi,myi}{j}{i});
-
-	  tmp = __plot_image_dims__{cf}{mxi,myi}{j}{i};
-
-	  x_dim = tmp(1);
-	  y_dim = tmp(2);
-	  x_origin = tmp(3);
-	  y_origin = tmp(4);
-	  dx = tmp(5);
-	  dy = tmp(6);
+	columns = __multiplot_xn__(cf);
+	rows = __multiplot_yn__(cf);
+	__gnuplot_raw__ (sprintf ("set size %g, %g;\n",
+				  __multiplot_xsize__(cf),
+				  __multiplot_ysize__(cf)));
 
-	  A = __plot_data__{cf}{mxi,myi}{j}{i};
-
-	  ## Let the file be deleted when Octave exits or
-	  ## `purge_tmp_files' is called.
-	  [fid, binary_file_name, msg] ...
-	      = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1);
-
-	  ## Gnuplot reads binary files very quickly.  However, the
-	  ## 'fwrite' below is much slower than using the current
-	  ## '__gnuplot_plot__' command.
-	  fwrite (fid, A(:), "float");
-	  fclose (fid);
+	xo = (mxi - 1.0) * __multiplot_xsize__(cf);
+	yo = (rows - myi) * __multiplot_ysize__(cf);
 
-	  __gnuplot_raw__ (sprintf ("\"%s\" binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using 1 %s '%s' with image",
-				    binary_file_name, x_dim, y_dim, x_origin,
-				    y_origin, dx, dy,
-				    gnuplot_command_title, label));
-	else
-	  usingstr = __plot_usingstr__{cf}{mxi,myi}{j}{i};
-	  fmtstr = __plot_fmtstr__{cf}{mxi,myi}{j}{i};
-	  withstr = __plot_withstr__{cf}{mxi,myi}{j}{i};
+	__gnuplot_raw__ (sprintf ("set origin %g, %g;\n", xo, yo));
 
-	  label = undo_string_escapes (__plot_key_labels__{cf}{mxi,myi}{j}{i});
+	__render_plot1__ (mxi, myi)
 
-	  __gnuplot_raw__ (sprintf ("'-' %s %s '%s' %s %s %s", usingstr,
-				    gnuplot_command_title, label, fmtstr,
-				    withstr));
-	endif
       endfor
     endfor
-
-    for j = 1:length (__plot_data__{cf}{mxi,myi})
-      for i = 1:length (__plot_data__{cf}{mxi,myi}{j})
-	this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j);
-	if (this_plot_data_type != 1)
-	  if (this_plot_data_type == 3)
-	    parametric = __plot_data_parametric__{cf}{mxi,myi}{j}{i};
-	  else
-	    parametric = false;
-	  endif
-	  __gnuplot_send_inline_data__ (__plot_data__{cf}{mxi,myi}{j}{i},
-					this_plot_data_type, parametric);
-	endif
-      endfor
-    endfor
-
-    if (! first)
-      __gnuplot_raw__ ("\n");
-    endif
-
+    __gnuplot_raw__ ("unset multiplot;\n");
+  else
+    __render_plot1__ (1, 1);
   endif
 
 endfunction
--- a/scripts/plot/print.m	Thu Nov 16 18:49:38 2006 +0000
+++ b/scripts/plot/print.m	Fri Nov 17 00:19:18 2006 +0000
@@ -126,6 +126,10 @@
 
 function print (varargin)
 
+  __plot_globals__;
+
+  mpmode = __multiplot_mode__(__current_figure__);
+
   orientation = orient ();
   use_color = 0; # 0=default, -1=mono, +1=color
   force_solid = 0; # 0=default, -1=dashed, +1=solid
@@ -249,9 +253,7 @@
 	options = strcat (options, " ", fontsize);
       endif
 
-      __gnuplot_raw__ ("set terminal push;\n");
-      __gnuplot_raw__ (sprintf ("set terminal postscript %s;\n", options));
-
+      new_terminal = strcat ("postscript ", options);
 
     elseif (strcmp (dev, "aifm") || strcmp (dev, "corel"))
       ## Adobe Illustrator, CorelDraw
@@ -267,8 +269,7 @@
 	options = strcat (options, " ", fontsize);
       endif
 
-      __gnuplot_raw__ ("set terminal push;\n");
-      __gnuplot_raw__ (sprintf ("set terminal %s %s;\n", dev, options));
+      new_terminal = strcat (dev, " ", options);
 
     elseif (strcmp (dev, "fig"))
       ## XFig
@@ -281,8 +282,8 @@
       if (! isempty (fontsize))
 	options = strcat (options, " fontsize ", fontsize);
       endif
-      __gnuplot_raw__ ("set terminal push;\n");
-      __gnuplot_raw__ (sprintf ("set terminal fig %s;\n", options));
+
+      new_terminal = strcat ("fig ", options);
 
     elseif (strcmp (dev, "emf"))
       ## Enhanced Metafile format
@@ -301,8 +302,8 @@
       if (! isempty (fontsize))
 	options = strcat (options, " ", fontsize);
       endif
-      __gnuplot_raw__ ("set terminal push;\n");
-      __gnuplot_raw__ (sprintf ("set terminal emf %s;\n", options));
+
+      new_terminal = strcat ("emf ", options);
 
     elseif (strcmp (dev, "png") || strcmp (dev, "pbm"))
       ## Portable network graphics, PBMplus
@@ -320,26 +321,28 @@
       ##eval (sprintf ("__gnuplot_set__ term %s mono medium", dev));
       ##endif
 
-      __gnuplot_raw__ ("set terminal push;\n");
-      __gnuplot_raw__ ("set terminal png large;\n")
+      new_terminal = "png large";
 
     elseif (strcmp (dev, "dxf") || strcmp (dev, "mf") || strcmp (dev, "hpgl"))
       ## AutoCad DXF, METAFONT, HPGL
-      __gnuplot_raw__ ("set terminal push;\n");
-      __gnuplot_raw__ (sprintf ("set terminal %s;\n", dev));
+      new_terminal = dev;
     endif
 
-    ## Gnuplot expects " around output file name
+    __gnuplot_raw__ ("set terminal push;\n");
+    __gnuplot_raw__ (sprintf ("set terminal %s;\n", new_terminal));
 
+    ## Gnuplot expects " around output file name
     __gnuplot_raw__ (sprintf ("set output \"%s\";\n", name));
-    __gnuplot_replot__
+
+    replot ();
 
   unwind_protect_cleanup
 
-    ## Restore init state
     __gnuplot_raw__ ("set terminal pop;\n");
     __gnuplot_raw__ ("set output;\n")
 
+    replot ();
+
   end_unwind_protect
 
   if (! isempty (convertname))
--- a/scripts/plot/subplot.m	Thu Nov 16 18:49:38 2006 +0000
+++ b/scripts/plot/subplot.m	Fri Nov 17 00:19:18 2006 +0000
@@ -129,17 +129,17 @@
         || __multiplot_xn__(cf) != columns
         || __multiplot_yn__(cf) != rows)
 
+      if (__multiplot_xn__(cf) < columns
+	  || __multiplot_yn__(cf) < rows)
+	__plot_data__{cf}{columns,rows} = [];
+      endif
+
       __multiplot_mode__(cf) = true;
       __multiplot_xn__(cf) = columns;
       __multiplot_yn__(cf) = rows;
       __multiplot_xsize__(cf) = 1 / columns;
       __multiplot_ysize__(cf) = 1 / rows;
 
-      __gnuplot_raw__ ("set multiplot;\n");
-
-      __gnuplot_raw__ (sprintf ("set size %g, %g;\n",
-				__multiplot_xsize__(cf),
-				__multiplot_ysize__(cf)));
     endif
 
     ## get the sub plot location
@@ -154,8 +154,6 @@
     xo = (xp - 1.0) * __multiplot_xsize__(cf);
     yo = (rows - yp) * __multiplot_ysize__(cf);
 
-    __gnuplot_raw__ (sprintf ("set origin %g, %g;\n", xo, yo));
-
   endif
 
 endfunction