changeset 8889:665b264b6a50

Compatible support of figure paper properties and resolution for the gnuplot backend.
author Ben Abbott <bpabbott@mac.com>
date Sat, 28 Feb 2009 19:36:09 -0500
parents 0c7b0049c023
children ae51d068bbd5
files scripts/ChangeLog scripts/plot/Makefile.in scripts/plot/__gnuplot_has_feature__.m scripts/plot/__go_draw_axes__.m scripts/plot/__go_draw_figure__.m scripts/plot/colorbar.m scripts/plot/gnuplot_drawnow.m scripts/plot/print.m scripts/plot/quiver3.m
diffstat 9 files changed, 286 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Feb 27 15:43:43 2009 -0500
+++ b/scripts/ChangeLog	Sat Feb 28 19:36:09 2009 -0500
@@ -1,3 +1,38 @@
+2009-02-28  Ben Abbott <bpabbott@mac.com>
+
+	* plot/print.m, plot/gnuplot_drawnow.m: Add compatible support for
+	specificying resolution of bitmap terminals, "-r<num>".
+
+	* plot/gnuplot_drawnow.m: Check that canvas size is only specified
+	one time.
+
+	* plot/gnuplot_drawnow.m, plot/__go_draw_figure__.m: Support papersize,
+	paperposition properties. Accommodate gnuplot's implicit margins for
+	postscript terminals. Remove internal function get_canvassize().
+
+	* plot/gnuplot_drawnow.m:
+	Terminate gnuplot "set term ..." with semicolon.
+	Specify vector terminals sizes in floating point.
+	Rename internal function isbackend() to output_to_screen().
+	Rename internal function gnuplot_term() to gnuplot_default_term().
+	Rename internal function isbitmap() to term_units_are_pixels().
+	Minor changes for coding conventions.
+
+	* plot/__actual_axis_position__.m, Makefile.in: New function to
+	determine position of rendered axes, including the effect of the
+	aspect ratio.
+	* plot/__gnuplot_has_feature__.m: Add new feature
+	"screen_coordinates_for_{lrtb}margin".
+	* plot/__go_draw_axes__.m, plot/colorbar.m: Enable axes to be positioned
+	using {lrtb}margins.
+	* plot/colorbar.m: Add to, and modify, demos.
+
+	* plot/print.m: Remove non-functional/commented code.
+	* plot/__go_draw_figure__.m: Remove non-functional code.
+	* plot/__gnuplot_has_feature__.m: Remove non-functional code.
+
+	* plot/quiver3.m: Add "clf" and "colormap(jet(64))" to demo.
+
 2009-02-27  John W. Eaton  <jwe@octave.org>
 
 	* set/complement.m: Call unique, not create_set.
--- a/scripts/plot/Makefile.in	Fri Feb 27 15:43:43 2009 -0500
+++ b/scripts/plot/Makefile.in	Sat Feb 28 19:36:09 2009 -0500
@@ -34,6 +34,7 @@
 INSTALL_DATA = @INSTALL_DATA@
 
 SOURCES = \
+  __actual_axis_position__.m \
   __add_datasource__.m \
   __area__.m \
   __axes_limits__.m \
--- a/scripts/plot/__gnuplot_has_feature__.m	Fri Feb 27 15:43:43 2009 -0500
+++ b/scripts/plot/__gnuplot_has_feature__.m	Sat Feb 28 19:36:09 2009 -0500
@@ -28,12 +28,13 @@
               "transparent_patches",
               "transparent_surface",
               "epslatex_implies_eps_filesuffix",
-              "epslatexstandalone_terminal"};
+              "epslatexstandalone_terminal",
+              "screen_coordinates_for_{lrtb}margin",};
 
   if (isempty (has_features))
     gnuplot_version = __gnuplot_version__ ();
-    versions = {"4.2.4", "4.3", "4.3", "4.2", "4.2"};
-    operators = {">", ">=", ">=", ">=", ">="};
+    versions = {"4.2.4", "4.3", "4.3", "4.2", "4.2", "4.3"};
+    operators = {">", ">=", ">=", ">=", ">=", ">="};
     have_features = logical (zeros (size (features)));
     for n = 1 : numel (have_features)
       has_features(n) = compare_versions (gnuplot_version, versions{n}, operators{n});
--- a/scripts/plot/__go_draw_axes__.m	Fri Feb 27 15:43:43 2009 -0500
+++ b/scripts/plot/__go_draw_axes__.m	Sat Feb 28 19:36:09 2009 -0500
@@ -23,20 +23,14 @@
 
 ## Author: jwe
 
-function __go_draw_axes__ (h, plot_stream, enhanced, mono)
+function __go_draw_axes__ (h, plot_stream, enhanced, mono, implicit_margin)
 
-  if (nargin == 4)
+  if (nargin >= 4 && nargin <= 5)
 
     axis_obj = __get__ (h);
 
     parent_figure_obj = get (axis_obj.parent);
 
-    pos = axis_obj.position;
-    fprintf (plot_stream, "set tmargin 0;\n");
-    fprintf (plot_stream, "set bmargin 0;\n");
-    fprintf (plot_stream, "set lmargin 0;\n");
-    fprintf (plot_stream, "set rmargin 0;\n");
-
     ## Set to false for plotyy axes.
     if (strcmp (axis_obj.tag, "plotyy"))
       ymirror = false;
@@ -44,14 +38,39 @@
       ymirror = true;
     endif
 
-    fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2));
-    fprintf (plot_stream, "set size %.15g, %.15g;\n", pos(3), pos(4));
+    nd = __calc_dimensions__ (axis_obj);
+    pos = axis_obj.position;
+    pos = pos - implicit_margin([1, 2, 1, 2]).*[1, 1, -0.5, -0.5];
+    if (__gnuplot_has_feature__ ("screen_coordinates_for_{lrtb}margin"))
+      if (strcmpi (axis_obj.dataaspectratiomode, "manual"))
+	pos = __actual_axis_position__ (axis_obj);
+      endif
+      if (nd == 2)
+	x = [1, 1];
+      else
+	## 3D plots need to be sized down to fit in the window.
+	x = 1.0 ./ sqrt([2, 2.5]);
+      endif
+      fprintf (plot_stream, "set tmargin screen %.15g;\n", pos(2)+pos(4)/2+x(2)*pos(4)/2);
+      fprintf (plot_stream, "set bmargin screen %.15g;\n", pos(2)+pos(4)/2-x(2)*pos(4)/2);
+      fprintf (plot_stream, "set lmargin screen %.15g;\n", pos(1)+pos(3)/2-x(1)*pos(3)/2);
+      fprintf (plot_stream, "set rmargin screen %.15g;\n", pos(1)+pos(3)/2+x(1)*pos(3)/2);
+    else
+      ## FIXME -- nothing should change for gnuplot 4.2.x.
+      fprintf (plot_stream, "set tmargin 0;\n");
+      fprintf (plot_stream, "set bmargin 0;\n");
+      fprintf (plot_stream, "set lmargin 0;\n");
+      fprintf (plot_stream, "set rmargin 0;\n");
 
-    if (strcmpi (axis_obj.dataaspectratiomode, "manual"))
-      r = axis_obj.dataaspectratio;
-      fprintf (plot_stream, "set size ratio %.15g;\n", -r(2)/r(1));
-    else
-      fputs (plot_stream, "set size noratio;\n");
+      fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2));
+      fprintf (plot_stream, "set size %.15g, %.15g;\n", pos(3), pos(4));
+
+      if (strcmpi (axis_obj.dataaspectratiomode, "manual"))
+        r = axis_obj.dataaspectratio;
+        fprintf (plot_stream, "set size ratio %.15g;\n", -r(2)/r(1));
+      else
+        fputs (plot_stream, "set size noratio;\n");
+      endif
     endif
 
     fputs (plot_stream, "unset label;\n");
@@ -270,8 +289,6 @@
 
     kids = axis_obj.children;
 
-    nd = __calc_dimensions__ (axis_obj);
-
     if (nd == 3)
       fputs (plot_stream, "set parametric;\n");
       fputs (plot_stream, "set style data lines;\n");
@@ -1975,3 +1992,4 @@
     typ = -1;
   endif
 endfunction
+
--- a/scripts/plot/__go_draw_figure__.m	Fri Feb 27 15:43:43 2009 -0500
+++ b/scripts/plot/__go_draw_figure__.m	Sat Feb 28 19:36:09 2009 -0500
@@ -23,27 +23,43 @@
 
 ## Author: jwe
 
-function __go_draw_figure__ (h, plot_stream, enhanced, mono)
+function __go_draw_figure__ (h, plot_stream, enhanced, mono, output_to_paper, implicit_margin)
 
-  if (nargin == 4)
+  if (nargin < 5)
+    output_to_paper = false;
+  elseif (nargin < 6)
+    ## Gnuplot has implicit margins for some output. For example, for postscript
+    ## the margin is 50pts. If not specified asssume 0.
+    implicit_margin = 0;
+  endif
+
+  if (nargin >= 4 && nargin <= 6)
     htype = get (h, "type");
     if (strcmp (htype, "figure"))
 
       ## Set figure properties here?
 
+      ## For output, determine the normalized paperposition.
+      if (output_to_paper)
+	orig_paper_units = get (h, "paperunits");
+	unwind_protect
+	  set (h, "paperunits", "inches");
+          paper_size = get (h, "papersize");
+          paper_position = get (h, "paperposition");
+          paper_position = paper_position ./ paper_size([1, 2, 1, 2]);
+	  implicit_margin = implicit_margin ./ paper_size([1, 2]);
+	unwind_protect_cleanup
+	  set (h, "paperunits", orig_paper_units);
+	end_unwind_protect
+      else
+	implicit_margin = implicit_margin * [1 1];
+      endif
+
       ## Get complete list of children.
       kids = allchild (h);
       nkids = length (kids);
 
       if (nkids > 0)
-	axes_count = 0;
-	for i = 1:nkids
-	  obj = __get__ (kids(i));
-	  switch (obj.type)
-	    case "axes"
-	      axes_count++;
-	  endswitch
-	endfor
 
 	fputs (plot_stream, "\nreset;\n");
 	fputs (plot_stream, "set autoscale fix;\n");
@@ -52,13 +68,29 @@
 	fputs (plot_stream, "set size 1, 1\n");
 
 	for i = 1:nkids
-	  obj = get (kids(i));
-	  switch (obj.type)
+	  type = get (kids(i), "type");
+	  switch (type)
 	    case "axes"
-	      __go_draw_axes__ (kids (i), plot_stream, enhanced, mono);
+	      ## Rely upon listener to convert axes position to "normalized" units.
+	      orig_axes_units = get (kids(i), "units");
+  	      orig_axes_position = get (kids(i), "position");
+	      unwind_protect
+		set (kids(i), "units", "normalized");
+		if (output_to_paper)
+	 	  axes_position_on_page = orig_axes_position .* paper_position([3, 4, 3 ,4]);
+		  axes_position_on_page(1:2) = axes_position_on_page(1:2) +  paper_position(1:2);
+		  set (kids(i), "position", axes_position_on_page);
+		  __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin);
+		else
+		  ## Return axes "units" and "position" back to their original values.
+		  __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin);
+		endif
+	      unwind_protect_cleanup
+		set (kids(i), "units", orig_axes_units);
+		set (kids(i), "position", orig_axes_position);
+	      end_unwind_protect
 	    otherwise
-	      error ("__go_draw_figure__: unknown object class, %s",
-		     obj.type);
+	      error ("__go_draw_figure__: unknown object class, %s", type);
 	  endswitch
 	endfor
 
--- a/scripts/plot/colorbar.m	Fri Feb 27 15:43:43 2009 -0500
+++ b/scripts/plot/colorbar.m	Sat Feb 28 19:36:09 2009 -0500
@@ -322,14 +322,24 @@
   cpos = [origin, sz];
 
   if (strcmpi (obj.dataaspectratiomode, "manual"))
-    r = obj.dataaspectratio;
-
-    if (pos(3) > pos(4))
-      if (vertical)
-	aspect = [1, 0.21, 1];
+    if (__gnuplot_has_feature__ ("screen_coordinates_for_{lrtb}margin"))
+      obj.position = pos;
+      actual_pos = __actual_axis_position__ (obj);
+      if (strfind (cbox, "outside"))
+	scale = 1.0;
       else
-	aspect = [0.21, 1, 1];
+	scale = 0.9;
       endif
+      if (sz(1) > sz(2))
+	dx = (1-scale)*actual_pos(3);
+	cpos(1) = actual_pos(1) + dx/2;
+	cpos(3) = actual_pos(3) - dx;
+      else
+	dy = (1-scale)*actual_pos(4);
+	cpos(2) = actual_pos(2) + dy/2;
+	cpos(4) = actual_pos(4) - dy;
+      endif
+      aspect = NaN;
     else
       if (vertical)
 	aspect = [1, 0.21, 1];
@@ -344,32 +354,31 @@
 endfunction
 
 %!demo
-%! hold off;
 %! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! imagesc(x)
 %! colorbar();
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! imagesc(x)
 %! colorbar("westoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! imagesc(x)
 %! colorbar("northoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! imagesc(x)
 %! colorbar("southoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! subplot(2,2,1)
 %! contour(peaks())
 %! colorbar("east");
@@ -384,7 +393,7 @@
 %! colorbar("south");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! subplot(2,2,1)
 %! imagesc(x)
@@ -400,7 +409,7 @@
 %! colorbar("southoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! subplot(1,2,1)
 %! imagesc(x)
@@ -412,7 +421,7 @@
 %! colorbar("westoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! subplot(1,2,1)
 %! imagesc(x)
@@ -424,7 +433,7 @@
 %! colorbar("southoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! subplot(2,1,1)
 %! imagesc(x)
@@ -436,7 +445,7 @@
 %! colorbar("westoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! subplot(2,1,1)
 %! imagesc(x)
@@ -448,7 +457,7 @@
 %! colorbar("southoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! subplot(1,2,1)
 %! imagesc(x)
@@ -458,7 +467,7 @@
 %! colorbar("westoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! subplot(1,2,1)
 %! imagesc(x)
@@ -468,7 +477,7 @@
 %! colorbar("southoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! subplot(2,1,1)
 %! imagesc(x)
@@ -478,7 +487,7 @@
 %! colorbar("westoutside");
 
 %!demo
-%! hold off;
+%! clf
 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 %! subplot(2,1,1)
 %! imagesc(x)
@@ -487,4 +496,51 @@
 %! imagesc(x)
 %! colorbar("southoutside");
 
+%!demo
+%! clf
+%! locations = {"northoutside", "north", "southoutside", "south",
+%!              "westoutside", "west", "eastoutside", "east"};
+%! n = 64;
+%! x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! x = x .* fliplr (x) / 32^2;
+%! for r = 1:2
+%!   for c = 1:4
+%!     n = 2*(c-1) + r;
+%!     subplot (2, 4, n)
+%!     contour (x)
+%!     xlim ([1, 64])
+%!     ylim ([1, 64])
+%!     set (gca, "clim", [0, 1])
+%!     colorbar (locations{n});
+%!   endfor
+%! endfor
 
+%!demo
+%! clf
+%! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! subplot(1,2,1)
+%! contour(x)
+%! axis square;
+%! colorbar("east");
+%! xlim ([1, 64])
+%! ylim ([1, 64])
+%! subplot(1,2,2)
+%! imagesc(x)
+%! axis square;
+%! colorbar()
+
+%!demo
+%! clf
+%! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
+%! subplot(1,2,1)
+%! contour(x)
+%! axis square;
+%! colorbar("east");
+%! xlim ([1, 64])
+%! ylim ([1, 64])
+%! subplot(1,2,2)
+%! contour(x)
+%! colorbar("west");
+%! xlim ([1, 64])
+%! ylim ([1, 64])
+
--- a/scripts/plot/gnuplot_drawnow.m	Fri Feb 27 15:43:43 2009 -0500
+++ b/scripts/plot/gnuplot_drawnow.m	Sat Feb 28 19:36:09 2009 -0500
@@ -38,14 +38,15 @@
     ## debug file.
     plot_stream = [];
     fid = [];
+    printing = ! output_to_screen (gnuplot_trim_term (term));
     unwind_protect
       plot_stream = open_gnuplot_stream (1, []);
-      enhanced = gnuplot_set_term (plot_stream (1), true, h, term, file);
-      __go_draw_figure__ (h, plot_stream, enhanced, mono);
+      [enhanced, implicit_margin] = gnuplot_set_term (plot_stream (1), true, h, term, file);
+      __go_draw_figure__ (h, plot_stream, enhanced, mono, printing, implicit_margin);
       if (nargin == 5)
         fid = fopen (debug_file, "wb");
         enhanced = gnuplot_set_term (fid, true, h, term, file);
-        __go_draw_figure__ (h, fid, enhanced, mono);
+        __go_draw_figure__ (h, fid, enhanced, mono, printing, implicit_margin);
       endif
     unwind_protect_cleanup
       if (! isempty (plot_stream))
@@ -65,7 +66,7 @@
       new_stream = false;
     endif
     enhanced = gnuplot_set_term (plot_stream (1), new_stream, h);
-    __go_draw_figure__ (h, plot_stream (1), enhanced, mono);
+    __go_draw_figure__ (h, plot_stream (1), enhanced, mono, 0);
     fflush (plot_stream (1));
   else
     print_usage ();
@@ -73,6 +74,15 @@
 
 endfunction
 
+function implicit_margin = gnuplot_implicit_margin (term, opts_str)
+  ## gnuplot has an implicit margin of 50pts for PS output.
+  if (strcmpi (term, "postscript") && isempty (strfind (opts_str, "eps")))
+    implicit_margin = 50/72;
+  else
+    implicit_margin = 0.0;
+  endif
+endfunction
+
 function plot_stream = open_gnuplot_stream (npipes, h)
   cmd = gnuplot_binary ();
   if (npipes > 1)
@@ -91,21 +101,27 @@
   endif
 endfunction
 
-function enhanced = gnuplot_set_term (plot_stream, new_stream, h, term, file)
+function [enhanced, implicit_margin] = gnuplot_set_term (plot_stream, new_stream, h, term, file)
   ## Generate the gnuplot "set terminal <term> ..." command.  Include
   ## the subset of properties "position", "units", "paperposition",
   ## "paperunits", "name", and "numbertitle".  When "term" originates
   ## from print.m, it may include gnuplot terminal options.
   if (nargin < 4)
     ## This supports the gnuplot backend.
-    term = gnuplot_term ();
+    term = gnuplot_default_term ();
     opts_str = "";
   else
     ## Get the one word terminal id and save the remaining as options to
     ## be passed on to gnuplot.  The terminal may respect the backend.
     [term, opts_str] = gnuplot_trim_term (term);
+    if (strcmpi (term, "pdf") && strcmpi (opts_str, "color"))
+      ## FIXME -- "color" for the pdf terminal produces a gnuplot error.
+      opts_str = "";
+    endif
   endif
 
+  implicit_margin = gnuplot_implicit_margin (term, opts_str);
+
   enhanced = gnuplot_is_enhanced_term (term);
 
   ## Set the terminal.
@@ -120,7 +136,7 @@
     if (! isempty (h) && isfigure (h))
 
       ## Generate gnuoplot title string for backend plot windows.
-      if (isbackend (term))
+      if (output_to_screen (term))
         fig.numbertitle = get (h, "numbertitle");
         fig.name = get (h, "name");
         if (strcmpi (get (h, "numbertitle"), "on"))
@@ -139,31 +155,44 @@
       else
         title_str = "";
       endif
-
-      if (isempty (strfind (opts_str, " size ")))
+      if (! (any (strfind (opts_str, " size ") > 0) 
+	  || any (strfind (opts_str, "size ") == 1)))
         ## Convert position to units used by gnuplot.
-        if (isbackend (term))
+        if (output_to_screen (term))
           ## Get figure size in pixels.
           [gnuplot_size, gnuplot_pos] = get_figsize (h);
         else
           ## Get size of the printed plot in inches.
-          gnuplot_size = get_canvassize (h);
-          ## If the output is a bitmap, convert to pixels.
-          if (isbitmap (term) || strcmpi (term, "svg"))
-            gnuplot_size = gnuplot_size * get (0, "screenpixelsperinch");
+          gnuplot_size = get_papersize (h);
+          if (term_units_are_pixels (term))
+ 	    ## Convert to inches using the property set by print().
+	    gnuplot_size = gnuplot_size * get (h, "__pixels_per_inch__");
+	  else
+	    ## Implicit margins are in units of "inches"
+	    gnuplot_size = gnuplot_size - implicit_margin;
           endif
         endif
+	[begin_match, end_match, te, match] = regexp (opts_str, "(\\s-r\\d+)|(^-r\\d+)");
+	if (! isempty (begin_match))
+	  error ("gnuplot_drawnow.m: specifying resultion, '%s', not supported for terminal '%s'",
+	         strtrim (match{1}), term)
+	endif
         if (all (gnuplot_size > 0))
           ## Set terminal size.
           terminals_with_size = {"emf", "gif", "jpeg", "latex", "pbm", ...
                                  "pdf", "png", "postscript", "svg", "wxt", ...
                                  "epslatex", "pstex", "pslatex"};
-          if (__gnuplot_has_feature__("x11_figure_position"))
+          if (__gnuplot_has_feature__ ("x11_figure_position"))
             terminals_with_size{end+1} = "x11";
           endif
           if (any (strncmpi (term, terminals_with_size, 3)))
-            size_str = sprintf ("size %d,%d", gnuplot_size(1), gnuplot_size(2));
-            if (strncmpi (term, "X11", 3))
+	    if (term_units_are_pixels (term))
+              size_str = sprintf ("size %d,%d", gnuplot_size(1), gnuplot_size(2));
+	    else
+              size_str = sprintf ("size %.15g,%.15g", gnuplot_size(1), gnuplot_size(2));
+	    endif
+            if (strncmpi (term, "X11", 3) && __gnuplot_has_feature__ ("x11_figure_position"))
+	      ## X11 allows the window to be positioned as well.
               screen_size = get (0, "screensize")(3:4);
               if (all (screen_size > 0))
                 ## For X11, set the figure positon as well as the size
@@ -174,12 +203,15 @@
                                     gnuplot_pos(1), gnuplot_pos(2));
               endif
             endif
-          elseif (any (strncmpi (term, {"aqua", "fig"}, 3)))
-            ## Aqua and Fig also have size, but the format is different.
+          elseif (strncmpi (term, "aqua", 3))
+            ## Aqua has size, but the format is different.
             size_str = sprintf ("size %d %d", gnuplot_size(1), gnuplot_size(2));
+          elseif (strncmpi (term, "fig", 3))
+            ## Fig also has size, but the format is different.
+            size_str = sprintf ("size %.15g %.15g", gnuplot_size(1), gnuplot_size(2));
           elseif (any (strncmpi (term, {"corel", "hpgl"}, 3)))
             ## The size for corel and hpgl are goes at the end (implicit).
-            size_str = sprintf ("%d %d",gnuplot_size(1), gnuplot_size(2));
+            size_str = sprintf ("%.15g %.15g",gnuplot_size(1), gnuplot_size(2));
           elseif (any (strncmpi (term, {"dxf"}, 3)))
             ## DXF uses autocad units.
             size_str = "";
@@ -228,7 +260,7 @@
         ## Options must go last.
         term_str = sprintf ("%s %s", term_str, opts_str);
       endif
-      fprintf (plot_stream, sprintf ("%s\n", term_str));
+      fprintf (plot_stream, sprintf ("%s;\n", term_str));
     else
       ## gnuplot will pick up the GNUTERM environment variable itself
       ## so no need to set the terminal type if not also setting the
@@ -241,9 +273,10 @@
       fprintf (plot_stream, "set output \"%s\";\n", file);
     endif
   endif
+
 endfunction
 
-function term = gnuplot_term ()
+function term = gnuplot_default_term ()
   term = getenv ("GNUTERM");
   ## If not specified, guess the terminal type.
   if (isempty (term))
@@ -280,7 +313,7 @@
   endif
   if (nargin < 1)
     ## Determine the default gnuplot terminal.
-    term = gnuplot_term ();
+    term = gnuplot_default_term ();
   endif
   have_enhanced = false;
   for n = 1 : length (enhanced_terminals)
@@ -292,18 +325,12 @@
   endfor
 endfunction
 
-function ret = isbackend (term)
-  if (nargin == 0)
-    term = gnuplot_term ();
-  endif
+function ret = output_to_screen (term)
   ret = any (strcmpi ({"aqua", "wxt", "x11", "windows", "pm"}, term));
 endfunction
 
-function ret = isbitmap (term)
-  if (nargin == 0)
-    term = gnuplot_term ();
-  endif
-  ret = any (strcmpi ({"png", "jpeg", "gif", "pbm"}, term));
+function ret = term_units_are_pixels (term)
+  ret = any (strcmpi ({"png", "jpeg", "gif", "pbm", "svg"}, term));
 endfunction
 
 function [fig_size, fig_pos] = get_figsize (h)
@@ -325,26 +352,9 @@
   fig_size(2) = max (min (fig_size(2), screensize(2)), 10-fig_pos(2));
 endfunction
 
-function plotsize = get_canvassize (h)
-  ## Returns the intended size of the plot on the page in inches. 
-  ## "canvas size" is a gnuplot term. Gnuplot doesn't explicity plot to
-  ## an area/position on a page. Instead it plots to a "canvas" of a 
-  ## explicit or implicit size.
-  t.points      = get (0, "screenpixelsperinch");
-  t.centimeters = 2.54;
-  t.inches      = 1.00;
-  papersize = get_papersize (h);
-  paperunits = get (h, "paperunits");
-  paperposition = get (h, "paperposition") / t.(paperunits);
-  if (strcmpi (paperunits, "normalized"))
-    plotsize = papersize .* paperposition(3:4);
-  else
-    plotsize = paperposition(3:4);
-  endif
-endfunction
-
 function papersize = get_papersize (h)
   ## Returns the papersize in inches
+  ## FIXME - a listener should hanlde this.
   persistent papertypes papersizes
   if (isempty (papertypes))
     papertypes = {"usletter", "uslegal", ...
--- a/scripts/plot/print.m	Fri Feb 27 15:43:43 2009 -0500
+++ b/scripts/plot/print.m	Sat Feb 28 19:36:09 2009 -0500
@@ -105,6 +105,9 @@
 ##   If the device is omitted, it is inferred from the file extension,
 ##   or if there is no filename it is sent to the printer as postscript.
 ##
+## @itemx -r@var{NUM}
+##   Resolution of bitmaps in pixels per inch.
+##
 ## @itemx -S@var{xsize},@var{ysize}
 ##   Plot size in pixels for PNG and SVG.  If using the command form of
 ##   the print function, you must quote the @var{xsize},@var{ysize}
@@ -140,6 +143,7 @@
   debug = false;
   debug_file = "octave-print-commands.log";
   special_flag = "textnormal";
+  resolution = "";
 
   old_fig = get (0, "currentfigure");
   unwind_protect
@@ -183,6 +187,8 @@
 	  endif
         elseif (length (arg) > 2 && arg(1:2) == "-S")
 	  size = arg(3:length(arg));
+        elseif (length (arg) > 2 && arg(1:2) == "-r")
+	  resolution = arg(3:length(arg));
         elseif (length (arg) >= 1 && arg(1) == "-")
 	  error ("print: unknown option `%s'", arg);
 	elseif (length (arg) > 0)
@@ -363,16 +369,12 @@
       ## that one perhaps has to write a separate printpng.m function.
       ## DAS
 
-      ## if (use_color >= 0)
-      ##	eval (sprintf ("__gnuplot_set__ term %s color medium", dev));
-      ##else
-      ##eval (sprintf ("__gnuplot_set__ term %s mono medium", dev));
-      ##endif
-
-      if (isempty (size))
+      if (isempty (size) && isempty (resolution))
         options = " large";
+      elseif (! isempty (size))
+        options = cstrcat (" size ", size);
       else
-        options = cstrcat (" size ", size);
+	options = "";
       endif
       new_terminal = cstrcat (dev, options);
 
@@ -414,6 +416,17 @@
 
     mono = use_color < 0;
 
+    if (isempty (resolution))
+      resolution = get (0, "screenpixelsperinch");
+    else
+      resolution = str2num (resolution);
+    endif
+    figure_properties = get (gcf);
+    if (! isfield (figure_properties, "__pixels_per_inch__"))
+      addproperty ("__pixels_per_inch__", gcf, "double", resolution);
+    endif
+    set (gcf, "__pixels_per_inch__", resolution)
+
     if (debug)
       drawnow (new_terminal, name, mono, debug_file);
     else
--- a/scripts/plot/quiver3.m	Fri Feb 27 15:43:43 2009 -0500
+++ b/scripts/plot/quiver3.m	Sat Feb 28 19:36:09 2009 -0500
@@ -85,6 +85,8 @@
 endfunction
 
 %!demo
+%! clf
+%! colormap (jet (64))
 %! [x,y]=meshgrid (-1:0.1:1); 
 %! z=sin(2*pi*sqrt(x.^2+y.^2)); 
 %! theta=2*pi*sqrt(x.^2+y.^2)+pi/2;
@@ -94,6 +96,7 @@
 %! hold off;
 
 %!demo
+%! clf
 %! [x, y, z] = peaks (25);
 %! surf (x, y, z);
 %! hold on;
@@ -101,3 +104,7 @@
 %! h = quiver3 (x, y, z, u, v, w);
 %! set (h, "maxheadsize", 0.33);
 %! hold off;
+
+%!demo
+%! shading interp
+