changeset 6459:5dc550e1f419

[project @ 2007-03-26 18:11:58 by jwe]
author jwe
date Mon, 26 Mar 2007 18:11:58 +0000
parents 6588b4fe0869
children fa6312d93730
files scripts/ChangeLog scripts/plot/__plt1__.m scripts/plot/__plt2__.m scripts/plot/__plt2mm__.m scripts/plot/__plt2mv__.m scripts/plot/__plt2ss__.m scripts/plot/__plt2vm__.m scripts/plot/__plt2vv__.m scripts/plot/__plt__.m scripts/plot/__pltopt1__.m scripts/plot/__pltopt__.m scripts/plot/plot.m scripts/plot/plot3.m
diffstat 13 files changed, 223 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/ChangeLog	Mon Mar 26 18:11:58 2007 +0000
@@ -1,3 +1,16 @@
+2007-03-26  John W. Eaton  <jwe@octave.org>
+
+	* plot/__plt1__.m, plot/__plt2__.m, plot/__plt2mm__.m,
+	lot/__plt2mv__.m, plot/__plt2ss__.m, plot/__plt2vm__.m,
+	plot/__plt2vv__.m: Accept properties in addtition to options struct.
+
+2007-03-26  David Bateman  <dbateman@free.fr>
+
+	* plot/plot3.m: Handle line properties.
+	* plot/plot.m: Update docstring.
+	* plot/__plotopt__.m, plot/__pltopt1__.m: New arg, err_on_invalid.
+	* plot/__plt__.m: Also gather properties.
+
 2007-03-26  Kim Hansen  <kimhanse@gmail.com>
 
 	* testfun/assert.m: Delete special check for empty objects.
--- a/scripts/plot/__plt1__.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/__plt1__.m	Mon Mar 26 18:11:58 2007 +0000
@@ -18,14 +18,14 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt1__ (@var{h}, @var{x1}, @var{fmt}, @var{key})
+## @deftypefn {Function File} {} __plt1__ (@var{h}, @var{x1}, @var{options}, @var{properties})
 ## @end deftypefn
 
 ## Author: jwe
 
-function retval = __plt1__ (h, x1, options)
+function retval = __plt1__ (h, x1, options, properties)
 
-  if (nargin < 2 || nargin > 3)
+  if (nargin < 2 || nargin > 4)
     print_usage ();
   endif
 
@@ -33,6 +33,10 @@
     options = __default_plot_options__ ();
   endif
 
+  if (nargin < 4)
+    properties = {};
+  endif
+
   if (! isstruct (options))
     error ("__plt1__: options must be a struct array");
   endif
@@ -53,6 +57,6 @@
     x1 = (1:nr)';
   endif
 
-  retval = __plt2__ (h, x1, x2, options);
+  retval = __plt2__ (h, x1, x2, options, properties);
 
 endfunction
--- a/scripts/plot/__plt2__.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/__plt2__.m	Mon Mar 26 18:11:58 2007 +0000
@@ -18,14 +18,14 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2__ (@var{h}, @var{x1}, @var{x2}, @var{options})
+## @deftypefn {Function File} {} __plt2__ (@var{h}, @var{x1}, @var{x2}, @var{options}, @var{properties})
 ## @end deftypefn
 
 ## Author: jwe
 
-function retval = __plt2__ (h, x1, x2, options)
+function retval = __plt2__ (h, x1, x2, options, properties)
 
-  if (nargin < 3 || nargin > 4)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
@@ -33,6 +33,10 @@
     options = __default_plot_options__ ();
   endif
 
+  if (nargin < 5)
+    properties = {};
+  endif
+
   if (! isstruct (options))
     error ("__plt1__: options must be a struct array");
   endif
@@ -48,23 +52,23 @@
   h_set = false;
   if (isscalar (x1))
     if (isscalar (x2))
-      retval = __plt2ss__ (h, x1, x2, options);
+      retval = __plt2ss__ (h, x1, x2, options, properties);
     else
       error ("__plt2__: invalid data for plotting");
     endif
   elseif (isvector (x1))
     if (isvector (x2))
-      retval = __plt2vv__ (h, x1, x2, options);
+      retval = __plt2vv__ (h, x1, x2, options, properties);
     elseif (ismatrix (x2))
-      retval = __plt2vm__ (h, x1, x2, options);
+      retval = __plt2vm__ (h, x1, x2, options, properties);
     else
       error ("__plt2__: invalid data for plotting");
     endif
   elseif (ismatrix (x1))
     if (isvector (x2))
-      retval = __plt2mv__ (h, x1, x2, options);
+      retval = __plt2mv__ (h, x1, x2, options, properties);
     elseif (ismatrix (x2))
-      retval = __plt2mm__ (h, x1, x2, options);
+      retval = __plt2mm__ (h, x1, x2, options, properties);
     else
       error ("__plt2__: invalid data for plotting");
     endif
--- a/scripts/plot/__plt2mm__.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/__plt2mm__.m	Mon Mar 26 18:11:58 2007 +0000
@@ -18,14 +18,14 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2mm__ (@var{h}, @var{x}, @var{y}, @var{options})
+## @deftypefn {Function File} {} __plt2mm__ (@var{h}, @var{x}, @var{y}, @var{options}, @var{properties})
 ## @end deftypefn
 
 ## Author: jwe
 
-function retval = __plt2mm__ (h, x, y, options)
+function retval = __plt2mm__ (h, x, y, options, properties)
 
-  if (nargin < 3 || nargin > 4)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
@@ -33,6 +33,10 @@
     options = __default_plot_options__ ();
   endif
 
+  if (nargin < 5)
+    properties = {};
+  endif
+
   [x_nr, x_nc] = size (x);
   [y_nr, y_nc] = size (y);
 
@@ -54,7 +58,7 @@
 	endif
 	retval(i) = line (x(:,i), y(:,i), "keylabel", tkey, "color", color,
 			  "linestyle", options(i).linestyle,
-			  "marker", options(i).marker);
+			  "marker", options(i).marker, properties{:});
       endfor
     else
       error ("__plt2mm__: arguments must be a matrices");
--- a/scripts/plot/__plt2mv__.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/__plt2mv__.m	Mon Mar 26 18:11:58 2007 +0000
@@ -18,14 +18,14 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2mv__ (@var{h}, @var{x}, @var{y}, @var{options})
+## @deftypefn {Function File} {} __plt2mv__ (@var{h}, @var{x}, @var{y}, @var{options}, @var{properties})
 ## @end deftypefn
 
 ## Author: jwe
 
-function retval = __plt2mv__ (h, x, y, options)
+function retval = __plt2mv__ (h, x, y, options, properties)
 
-  if (nargin < 3 || nargin > 4)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
@@ -33,6 +33,10 @@
     options = __default_plot_options__ ();
   endif
 
+  if (nargin < 5)
+    properties = {};
+  endif
+
   [x_nr, x_nc] = size (x);
   [y_nr, y_nc] = size (y);
 
@@ -70,7 +74,7 @@
       endif
       retval(i) = line (x(:,i), y, "keylabel", tkey, "color", color,
 			"linestyle", options(i).linestyle,
-			"marker", options(i).marker);
+			"marker", options(i).marker, properties{:});
     endfor
   else
     error ("__plt2mv__: arguments must be a matrices");
--- a/scripts/plot/__plt2ss__.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/__plt2ss__.m	Mon Mar 26 18:11:58 2007 +0000
@@ -18,14 +18,14 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2ss__ (@var{h}, @var{x}, @var{y}, @var{options})
+## @deftypefn {Function File} {} __plt2ss__ (@var{h}, @var{x}, @var{y}, @var{options}, @var{properties})
 ## @end deftypefn
 
 ## Author: jwe
 
-function retval = __plt2ss__ (h, x, y, options)
+function retval = __plt2ss__ (h, x, y, options, properties)
 
-  if (nargin < 3 || nargin > 4)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
@@ -33,6 +33,10 @@
     options = __default_plot_options__ ();
   endif
 
+  if (nargin < 5)
+    properties = {};
+  endif
+
   if (numel (options) > 1)
     options = options(1);
   endif
@@ -51,7 +55,7 @@
     endif
     retval = line (x, y, "keylabel", key, "color", color,
 		   "linestyle", options.linestyle,
-		   "marker", options.marker);
+		   "marker", options.marker, properties{:});
   else
     error ("__plt2ss__: arguments must be scalars");
   endif
--- a/scripts/plot/__plt2vm__.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/__plt2vm__.m	Mon Mar 26 18:11:58 2007 +0000
@@ -18,14 +18,14 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2vm__ (@var{h}, @var{x}, @var{y}, @var{options})
+## @deftypefn {Function File} {} __plt2vm__ (@var{h}, @var{x}, @var{y}, @var{options}, @var{properties})
 ## @end deftypefn
 
 ## Author: jwe
 
-function retval = __plt2vm__ (h, x, y, options)
+function retval = __plt2vm__ (h, x, y, options, properties)
 
-  if (nargin < 3 || nargin > 4)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
@@ -33,6 +33,10 @@
     options = __default_plot_options__ ();
   endif
 
+  if (nargin < 5)
+    properties = {};
+  endif
+
   [x_nr, x_nc] = size (x);
   [y_nr, y_nc] = size (y);
 
@@ -70,7 +74,7 @@
       endif
       retval(i) = line (x, y(:,i), "keylabel", tkey, "color", color,
 			"linestyle", options(i).linestyle,
-			"marker", options(i).marker);
+			"marker", options(i).marker, properties{:});
     endfor
   else
     error ("__plt2vm__: arguments must be a matrices");
--- a/scripts/plot/__plt2vv__.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/__plt2vv__.m	Mon Mar 26 18:11:58 2007 +0000
@@ -18,14 +18,14 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __plt2vv__ (@var{h}, @var{x}, @var{y}, @var{options})
+## @deftypefn {Function File} {} __plt2vv__ (@var{h}, @var{x}, @var{y}, @var{options}, @var{properties})
 ## @end deftypefn
 
 ## Author: jwe
 
-function retval = __plt2vv__ (h, x, y, options)
+function retval = __plt2vv__ (h, x, y, options, properties)
 
-  if (nargin < 3 || nargin > 4)
+  if (nargin < 3 || nargin > 5)
     print_usage ();
   endif
 
@@ -33,6 +33,10 @@
     options = __default_plot_options__ ();
   endif
 
+  if (nargin < 5)
+    properties = {};
+  endif
+
   if (numel (options) > 1)
     options = options(1);
   endif
@@ -65,7 +69,7 @@
     endif
     retval = line (x, y, "keylabel", key, "color", color,
 		   "linestyle", options.linestyle,
-		   "marker", options.marker);
+		   "marker", options.marker, properties{:});
   else
     error ("__plt2vv__: vector lengths must match");
   endif
--- a/scripts/plot/__plt__.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/__plt__.m	Mon Mar 26 18:11:58 2007 +0000
@@ -33,6 +33,8 @@
 
     x_set = false;
     y_set = false;
+    property_set = false;
+    properties = {};
 
     ## Gather arguments, decode format, gather plot strings, and plot lines.
 
@@ -42,8 +44,10 @@
 
       if (nargs == 0)
 	## Force the last plot when input variables run out.
+	next_cell = {};
 	next_arg = {""};
       else
+	next_cell = varargin(k);
 	next_arg = varargin{k++};
       endif
 
@@ -51,12 +55,32 @@
 
       if (ischar (next_arg) || iscellstr (next_arg))
 	if (x_set)
-	  options = __pltopt__ (caller, next_arg);
+	  [options, valid] = __pltopt__ (caller, next_arg, false);
+	  if (! valid)
+	    if (nargs == 0)
+	      error ("%s: properties must appear followed by a value", caller);
+	    endif
+	    properties = [properties, [next_cell, varargin(k++)]];
+	    nargs--;
+	    continue;
+	  else
+	    while (nargs > 0 && ischar (varargin{k}))
+	      if (nargs < 2)
+		error ("%s: properties must appear followed by a value",
+		       caller);
+	      endif
+	      properties = [properties, varargin(k:k+1)];
+	      k += 2;
+	      nargs -= 2;
+	    endwhile
+	  endif
 	  if (y_set)
-	    tmp = __plt2__ (h, x, y, options);
+	    tmp = __plt2__ (h, x, y, options, properties);
+	    properties = {};
 	    retval = [retval; tmp];
 	  else
-	    tmp = __plt1__ (h, x, options);
+	    tmp = __plt1__ (h, x, options, properties);
+	    properties = {};
 	    retval = [retval; tmp];
 	  endif
 	  x_set = false;
@@ -67,10 +91,11 @@
       elseif (x_set)
 	if (y_set)
 	  options = __pltopt__ (caller, {""});
-	  tmp = __plt2__ (h, x, y, options);
+	  tmp = __plt2__ (h, x, y, options, properties);
 	  retval = [retval; tmp];
 	  x = next_arg;
 	  y_set = false;
+	  properties = {};
 	else
 	  y = next_arg;
 	  y_set = true;
@@ -86,7 +111,9 @@
     msg = sprintf ("%s (y)\n", caller);
     msg = sprintf ("%s       %s (x, y, ...)\n", msg, caller);
     msg = sprintf ("%s       %s (x, y, fmt, ...)", msg, caller);
+    msg = sprintf ("%s       %s (x, y, property, value, ...)", msg, caller);
     usage (msg);
   endif
 
 endfunction
+  
--- a/scripts/plot/__pltopt1__.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/__pltopt1__.m	Mon Mar 26 18:11:58 2007 +0000
@@ -27,13 +27,14 @@
 ## Adapted-By: jwe
 ## Maintainer: jwe
 
-function options = __pltopt1__ (caller, opt)
+function [options, valid] = __pltopt1__ (caller, opt, err_on_invalid)
 
   options = __default_plot_options__ ();
+  valid = true;
 
   more_opts = 1;
 
-  if (nargin != 2)
+  if (nargin != 2 && nargin != 3)
     print_usage ();
   endif
 
@@ -90,10 +91,22 @@
 	  options.key = undo_string_escapes (opt(2:t));
 	  n = t+1;
 	else
-          error ("%s: unfinished key label", caller);
+	  if (err_on_invalid)
+            error ("%s: unfinished key label", caller);
+	  else
+	    valid = false;
+	    options = __default_plot_options__ ();
+	    return;
+	  endif
         endif
       else
-	error ("%s: unrecognized format character: `%s'", caller, topt);
+	if (err_on_invalid)
+	  error ("%s: unrecognized format character: `%s'", caller, topt);
+	else
+	  valid = false;
+	  options = __default_plot_options__ ();
+	  return;
+	endif
       endif
     endif
     opt(1:n) = [];
--- a/scripts/plot/__pltopt__.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/__pltopt__.m	Mon Mar 26 18:11:58 2007 +0000
@@ -88,9 +88,15 @@
 
 ## Author: jwe
 
-function options = __pltopt__ (caller, opt)
+function [options, valid] = __pltopt__ (caller, opt, err_on_invalid)
+
+  valid = true;
+  options =  __default_plot_options__ ();
 
-  if (nargin == 2 && nargout == 1)
+  if ((nargin == 2 || nargin == 3) && (nargout == 1 || nargout == 2))
+    if (nargin == 2)
+      err_on_invalid = true;
+    endif
     if (ischar (opt))
       nel = rows (opt);
     elseif (iscellstr (opt))
@@ -102,7 +108,10 @@
       opt = cellstr (opt);
     endif
     for i = nel:-1:1
-      options(i) = __pltopt1__ (caller, opt{i});
+      [options(i), valid] = __pltopt1__ (caller, opt{i}, err_on_invalid);
+      if (! err_on_invalid && ! valid)
+	return;
+      endif
     endfor
   else
     print_usage ();
--- a/scripts/plot/plot.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/plot.m	Mon Mar 26 18:11:58 2007 +0000
@@ -37,13 +37,20 @@
 ## If more than one argument is given, they are interpreted as
 ##
 ## @example
-## plot (@var{x}, @var{y}, @var{fmt} ...)
+## plot (@var{x}, @var{y}, @var{fmt}, @dots{})
 ## @end example
 ##
 ## @noindent
-## where @var{y} and @var{fmt} are optional, and any number of argument
-## sets may appear.  The @var{x} and @var{y} values are
-## interpreted as follows:
+## or as
+##
+## @example
+## plot (@var{x}, @var{y}, @var{property}, @var{value}, @dots{})
+## @end example
+##
+## @noindent
+## where @var{y}, @var{fmt}, @var{property} and @var{value} are optional,
+## and any number of argument sets may appear.  The @var{x} and @var{y} 
+## values are interpreted as follows:
 ##
 ## @itemize @bullet
 ## @item
@@ -135,6 +142,9 @@
 ## Note that the last semi-colon is required and will generate an error if
 ## it is left out.
 ##
+## If a @var{property} is given it must be followed by @var{value}.  The
+## property value pairs are applied to the lines drawn by @code{plot}.
+##
 ## Here are some plot examples:
 ##
 ## @example
@@ -146,11 +156,11 @@
 ## color 4 (magenta) and @code{y4} with points displayed as @samp{+}.
 ##
 ## @example
-## plot (b, "*")
+## plot (b, "*", "markersize", 3)
 ## @end example
 ##
 ## This command will plot the data in the variable @code{b} will be plotted
-## with points displayed as @samp{*}.
+## with points displayed as @samp{*} with a marker size of 3.
 ##
 ## @example
 ## t = 0:0.1:6.3;
--- a/scripts/plot/plot3.m	Mon Mar 26 16:55:33 2007 +0000
+++ b/scripts/plot/plot3.m	Mon Mar 26 18:11:58 2007 +0000
@@ -98,12 +98,23 @@
   x_set = 0;
   y_set = 0;
   z_set = 0;
+  property_set = 0;
+  fmt_set = 0;
+  properties = {};
 
   idx = 0;
 
   ## Gather arguments, decode format, and plot lines.
-  for arg = 1:nargin
+  arg = 0;
+  while (arg++ < nargin)
     new = varargin{arg};
+    new_cell = varargin(arg);
+
+    if (property_set)
+      properties = [properties, new_cell];
+      property_set = 0;
+      continue;
+    endif
 
     if (ischar (new))
       if (! z_set)
@@ -127,7 +138,28 @@
 	  z_set = 1;
 	endif
       endif
-      options = __pltopt__ ("plot3", new);
+
+      if (! fmt_set)
+	[options, valid] = __pltopt__ ("plot3", new, false);
+	if (! valid)
+	  properties = [properties, new_cell];
+	  property_set = 1;
+	  continue;
+	else
+	  fmt_set = 1;
+	  while (arg < nargin && ischar (varargin{arg+1}))
+	    if (nargin - arg < 2)
+	      error ("plot3: properties must appear followed by a value");
+	    endif
+	    properties = [properties, varargin(arg:arg+1)];
+	    arg += 2;
+	  endwhile
+	endif
+      else
+	properties = [properties, new_cell];
+	property_set = 1;
+	continue;
+      endif
 
       if (isvector (x) && isvector (y))
 	if (isvector (z))
@@ -149,15 +181,20 @@
       if (! isempty (key))
 	set (gca (), "key", "on");
       endif
+      color = options.color;
+      if (isempty (options.color))
+	color = __next_line_color__ ();
+      endif
 
-      tmp(++idx) = line (x(:), y(:), z(:), "keylabel", key,
-			 "color", options.color,
+      tmp(++idx) = line (x(:), y(:), z(:),  "keylabel", key, "color", color,
 			 "linestyle", options.linestyle,
-			 "marker", options.marker);
+			 "marker", options.marker, properties{:});
 
       x_set = 0;
       y_set = 0;
       z_set = 0;
+      fmt_set = 0;
+      properties = {};
     elseif (! x_set)
       x = new;
       x_set = 1;
@@ -184,14 +221,32 @@
 	error ("plot3: x, y, and z must have the same shape");
       endif
 
-      tmp(++idx) = line (x(:), y(:), z(:));
+      options =  __default_plot_options__ ();
+      key = options.key;
+      if (! isempty (key))
+	set (gca (), "key", "on");
+      endif
+      color = options.color;
+      if (isempty (color))
+	color = __next_line_color__ ();
+      endif
+
+      tmp(++idx) = line (x(:), y(:), z(:),  "keylabel", key, "color", color,
+			 "linestyle", options.linestyle,
+			 "marker", options.marker, properties{:});
 
       x = new;
       y_set = 0;
       z_set = 0;
+      fmt_set = 0;
+      properties = {};
     endif
 
-  endfor
+  endwhile
+
+  if (property_set)
+    error ("plot3: properties must appear followed by a value");
+  endif
 
   ## Handle last plot.
 
@@ -230,8 +285,19 @@
       error ("plot3: x, y, and z must have the same shape");
     endif
 
-    tmp(++idx) = line (x(:), y(:), z(:));
+    options =  __default_plot_options__ ();
+    key = options.key;
+    if (! isempty (key))
+      set (gca (), "key", "on");
+    endif
+    color = options.color;
+    if (isempty (color))
+      color = __next_line_color__ ();
+    endif
 
+    tmp(++idx) = line (x(:), y(:), z(:),  "keylabel", key, "color", color,
+		       "linestyle", options.linestyle,
+		       "marker", options.marker, properties{:});
   endif
 
   set (gca (), "view", [-37.5, 30]);