changeset 7746:95dce69538ec

Allow additional options to stairs plots
author David Bateman <dbateman@free.fr>
date Thu, 01 May 2008 18:34:39 +0200
parents 0ff0fc033f28
children 7a0317f740f7
files scripts/ChangeLog scripts/plot/plot.m scripts/plot/stairs.m
diffstat 3 files changed, 56 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Wed Apr 30 17:51:02 2008 -0400
+++ b/scripts/ChangeLog	Thu May 01 18:34:39 2008 +0200
@@ -3,6 +3,12 @@
 	* elfun/acot.m, elfun/acsc.m, elfun/acsch.m, elfun/asec.m,
 	elfun/asech.m, specfun/pow2.m: Fix tests.
 
+2008-05-01  David Bateman  <dbateman@free.fr>
+
+	* plot/plot.m: Remove documentation of 'L' option.
+	* plot/stairs.m: Allow axis handles, properties and linespecs to
+	be passed.
+
 2008-04-30  Jaroslav Hajek <highegg@gmail.com>
 
 	* specfun/log2.m: Delete. 
--- a/scripts/plot/plot.m	Wed Apr 30 17:51:02 2008 -0400
+++ b/scripts/plot/plot.m	Thu May 01 18:34:39 2008 +0200
@@ -109,9 +109,6 @@
 ## @item ^
 ## Set impulses plot style.
 ##
-## @item L
-## Set steps plot style.
-##
 ## @item @var{n}
 ## Interpreted as the plot color if @var{n} is an integer in the range 1 to
 ## 6.
--- a/scripts/plot/stairs.m	Wed Apr 30 17:51:02 2008 -0400
+++ b/scripts/plot/stairs.m	Thu May 01 18:34:39 2008 +0200
@@ -19,6 +19,10 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} stairs (@var{x}, @var{y})
+## @deftypefnx {Function File} {} stairs (@dots{}, @var{style})
+## @deftypefnx {Function File} {} stairs (@dots{}, @var{prop}, @var{val})
+## @deftypefnx {Function File} {} stairs (@var{h}, @dots{})
+## @deftypefnx {Function File} {@var{h} =} stairs (@dots{})
 ## Produce a stairstep plot.  The arguments may be vectors or matrices.
 ##
 ## If only one argument is given, it is taken as a vector of y-values
@@ -49,20 +53,46 @@
 
 ## Author: jwe
 
-function [xs, ys] = stairs (x, y)
+function [xs, ys] = stairs (varargin)
 
-  if (nargin < 1 || nargin > 2)
-    print_usage ();
-  endif
+  [ax, varargin, nargin] = __plt_get_axis_arg__ ("stairs", varargin{:});
 
-  if (nargin == 1)
-    if (ismatrix (x))
-      if (isvector (x))
-	x = x(:);
+  if (nargin < 1)
+    print_usage ();
+  else
+    if (nargout > 1)
+      [h, xs, ys] = __stairs__ (false, varargin{:});
+    else
+      oldax = gca ();
+      unwind_protect
+	axes (ax);
+	newplot ();
+	[h, xxs, yys] = __stairs__ (true, varargin{:});
+      unwind_protect_cleanup
+	axes (oldax);
+      end_unwind_protect
+    endif
+    if (nargout == 1)
+      xs = h;
+    endif
+  endif
+endfunction
+
+function [h, xs, ys] = __stairs__ (doplot, varargin)
+
+  if (nargin == 1 || ischar (varargin{2}))
+    idx = 1;
+    y = varargin {1};
+    if (ismatrix (y))
+      if (isvector (y))
+	y = y(:);
       endif
-      y = x;
       x = 1:rows (y);
     endif
+  else
+    idx = 2;
+    x = varargin{1};
+    y = varargin{2};
   endif
 
   if (ndims (x) > 2 || ndims (y) > 2)
@@ -93,25 +123,24 @@
 
   len = 2*nr - 1;
 
-  tmp_xs = tmp_ys = zeros (len, nc);
+  xs = ys = zeros (len, nc);
 
-  tmp_xs(1,:) = x(1,:);
-  tmp_ys(1,:) = y(1,:);
+  xs(1,:) = x(1,:);
+  ys(1,:) = y(1,:);
 
-  tmp_x = x(2:nr,:);
+  x = x(2:nr,:);
   ridx = 2:2:len-1;
-  tmp_xs(ridx,:) = tmp_x;
-  tmp_ys(ridx,:) = y(1:nr-1,:);
+  xs(ridx,:) = x;
+  ys(ridx,:) = y(1:nr-1,:);
 
   ridx = 3:2:len;
-  tmp_xs(ridx,:) = tmp_x;
-  tmp_ys(ridx,:) = y(2:nr,:);
+  xs(ridx,:) = x;
+  ys(ridx,:) = y(2:nr,:);
 
-  if (nargout == 0)
-    plot (tmp_xs, tmp_ys);
+  if (doplot)
+    h = plot (xs, ys, varargin{idx+1:end});
   else
-    xs = tmp_xs;
-    ys = tmp_ys;
+    h = 0;
   endif
 
 endfunction