octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: meshz, and leading axis handles to mesh, meshc and surface


From: David Bateman
Subject: Re: meshz, and leading axis handles to mesh, meshc and surface
Date: Wed, 28 Nov 2007 17:29:50 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

John W. Eaton wrote:
> | Here is a patch that at least addresses this issue for the functions
> | that rely on __plt_get_axis_arg__ as the fix was small. Should we
> | convert the functions that probe the axes themselves to use
> | __plt_get_axis_arg__?
>
> I think it would be best to use a consistent method, so yes.
>
> Thanks,
>   
Then what about something like the attached.. There is one inconsistency
with this patch. If you want to do something like "[x,y,z] = sphere()"
you don't want a figure at all and therefore the call to gca() in
__plt_get_axis_handle__ should be avoided. My solution was to not call
gca() in __plt_get_axis_handle__ but rather to return a NaN. Then I
adapted axes() to accept a NaN as a valid axis and treat it as a gca().
The issue with this is that it is not matlab compatible to accept a NaN
to axes().

Can you think of a better solution that doesn't need a lot of special
casing in the functions like bar, sphere etc that can return values
rather than plot anything?

Regards
David



-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

--- ./scripts/plot/__bar__.m.~1.13.~    2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/__bar__.m    2007-11-28 14:56:32.035202509 +0100
@@ -22,22 +22,15 @@
 
 function varargout = __bar__ (vertical, func, varargin)
 
+  [h, varargin, nargin] = __plt_get_axis_arg__ (func, varargin{:});
   varargout = cell (nargout, 1);
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("%s: expecting first argument to be an axes object", func);
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (h);
-      [varargout{:}] = __bar2__ (h, vertical, func, varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
-    [varargout{:}] = __bar2__ (gca (), vertical, func, varargin{:});
-  endif
+  oldh = gca ();
+  unwind_protect
+    axes (h);
+    [varargout{:}] = __bar2__ (h, vertical, func, varargin{:});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
 
 endfunction
 
--- ./scripts/plot/caxis.m.~1.1.~       2007-11-15 23:48:58.000000000 +0100
+++ ./scripts/plot/caxis.m      2007-11-28 14:57:42.668589022 +0100
@@ -39,31 +39,19 @@
 
 function varargout = caxis (varargin)
 
-  if (nargin > 0 && isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("caxis: expecting first argument to be an axes object");
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (h);
-      varargout = cell (max (nargin == 1, nargout), 1);
-      if (isempty (varargout))
-       __caxis__ (h, varargin{2:end});
-      else
-        [varargout{:}] = __caxis__ (h, varargin{2:end});
-      endif
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("caxis", varargin{:});
+  oldh = gca ();
+  unwind_protect
+    axes (h);
     varargout = cell (max (nargin == 0, nargout), 1);
     if (isempty (varargout))
-      __caxis__ (gca (), varargin{:});
+      __caxis__ (h, varargin{:});
     else
-      [varargout{:}] = __caxis__ (gca (), varargin{:});
+      [varargout{:}] = __caxis__ (h, varargin{:});
     endif
-  endif
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
 
 endfunction
 
--- ./scripts/plot/scatter.m.~1.2.~     2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/scatter.m    2007-11-28 16:22:24.949330290 +0100
@@ -56,24 +56,19 @@
 
 function retval = scatter (varargin)
 
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("scatter", varargin{:});
+
   if (nargin < 2)
     print_usage ();
-  elseif (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("scatter: expecting first argument to be an axes object");
-    endif
+  else
     oldh = gca ();
     unwind_protect
       axes (h);
       newplot ();
-      tmp = __scatter__ (h, 2, "scatter", varargin{2:end});
+      tmp = __scatter__ (h, 2, "scatter", varargin{:});
     unwind_protect_cleanup
       axes (oldh);
     end_unwind_protect
-  else
-    newplot ();
-    tmp = __scatter__ (gca (), 2, "scatter", varargin{:});
   endif
 
   if (nargout > 0)
--- ./scripts/plot/contourf.m.~1.2.~    2007-11-13 19:37:24.000000000 +0100
+++ ./scripts/plot/contourf.m   2007-11-28 15:05:35.404569284 +0100
@@ -59,7 +59,8 @@
 
 function varargout = contourf (varargin)
 
-  [X, Y, Z, lvl, ax, patch_props] = parse_args (varargin);
+  [ax, varargin] = __plt_get_axis_arg__ ("contourf", varargin{:});
+  [X, Y, Z, lvl, patch_props] = parse_args (varargin);
   [nr, nc] = size (Z);
   [minx, maxx] = deal (min (X(:)), max (X(:)));
   [miny, maxy] = deal (min (Y(:)), max (Y(:)));
@@ -183,19 +184,11 @@
 
 endfunction
 
-function [X, Y, Z, lvl, ax, patch_props] = parse_args (arg)
+function [X, Y, Z, lvl, patch_props] = parse_args (arg)
 
   patch_props = {};
   nolvl = false;
 
-  if (isinteger (arg{1}) && ishandle (arg{1})
-      && strncmpi (get (arg{1}, "type"), "axis", 4))
-    ax = arg{1};
-    arg{1} = [];
-  else
-    ax = gca ();
-  endif
-
   for n = 1:numel (arg)
     if (ischar (arg{n}))
       patch_props = arg(n:end);
--- ./scripts/plot/__axes_limits__.m.~1.2.~     2007-11-28 08:30:06.000000000 
+0100
+++ ./scripts/plot/__axes_limits__.m    2007-11-28 14:51:59.119093549 +0100
@@ -22,21 +22,12 @@
   retval = [];
   fcnmode = sprintf("%smode", fcn);
 
-  if (nargin > 1 && isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    off = 1;
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("%s: expecting first argument to be an axes object", fcn);
-    endif
-  else
-    off = 0;
-    h = gca ();
-  endif
+  [h, varargin, nargin] = __plt_get_axis_arg__ (fcn, varargin{:});
 
-  if (nargin == off + 1)
+  if (nargin == 0)
     retval = get (h, fcn);
   else
-    arg = varargin{off + 1};
+    arg = varargin{1};
 
     if (ischar (arg))
       arg = tolower (arg);
--- ./scripts/plot/fill.m.~1.3.~        2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/fill.m       2007-11-28 17:09:36.031118088 +0100
@@ -27,37 +27,13 @@
 
 function h = fill (varargin)
 
+  [h, varargin] = __plt_get_axis_arg__ ("fill", varargin{:});
   htmp = [];
+  iargs = __find_patches__ (varargin{:});
+  oldh = gca ();
+  unwind_protect
+    axes (h);
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("fill: expecting first argument to be an axes object");
-    endif
-
-    iargs = __find_patches__ (varargin{:}) + 1;
-    oldh = gca ();
-    unwind_protect
-      axes (h);
-
-      for i = 1 : length (iargs)
-       if (i == length (iargs))
-         args = varargin (iargs(i):end);
-        else
-         args = varargin (iargs(i):iargs(i+1)-1);
-       endif
-       newplot ();
-       [tmp, fail] = __patch__ (h, args{:});
-       if (fail)
-         print_usage();
-       endif
-       htmp (end + 1) = tmp;
-      endfor
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
-    iargs = __find_patches__ (varargin{:});
     for i = 1 : length (iargs)
       if (i == length (iargs))
        args = varargin (iargs(i):end);
@@ -65,16 +41,20 @@
         args = varargin (iargs(i):iargs(i+1)-1);
       endif
       newplot ();
-      [tmp, fail] = __patch__ (gca (), args{:});
+      [tmp, fail] = __patch__ (h, args{:});
       if (fail)
        print_usage();
       endif
       htmp (end + 1) = tmp;
     endfor
-  endif
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
+
   if (nargout > 0)
     h = htmp;
   endif
+
 endfunction
 
 function iargs = __find_patches__ (varargin)
--- ./scripts/plot/__plt_get_axis_arg__.m.~1.7.~        2007-10-13 
06:52:11.000000000 +0200
+++ ./scripts/plot/__plt_get_axis_arg__.m       2007-11-28 16:51:07.078698775 
+0100
@@ -20,13 +20,13 @@
 
 ## Author: jwe
 
-function [h, varargin] = __plt_get_axis_arg__ (caller, varargin)
+function [h, varargin, narg] = __plt_get_axis_arg__ (caller, varargin)
 
   if (nargin > 1 && length (varargin) > 0 && ishandle (varargin{1}))
     tmp = varargin{1};
     obj = get (tmp);
-    if (strcmp (obj.type, "axes"))
-      h = tmp;
+    if (strcmp (obj.type, "axes") || strcmp (obj.type, "hggroup"))
+      h = ancestor (tmp, "axes");
       varargin(1) = [];
       if (isempty (varargin))
        varargin = {};
@@ -35,10 +35,12 @@
       error ("%s: expecting first argument to be axes handle", caller);
     endif
   else
-    h = gca ();
+    h = NaN;
     if (nargin < 2)
       varargin = {};
     endif
   endif
 
+  narg = length (varargin);
+
 endfunction
--- ./scripts/plot/surf.m.~1.3.~        2007-11-09 22:14:01.000000000 +0100
+++ ./scripts/plot/surf.m       2007-11-28 17:10:21.364804067 +0100
@@ -31,16 +31,21 @@
 
 function h = surf (varargin)
 
-  newplot ();
+  [h, varargin] = __plt_get_axis_arg__ ("surf", varargin{:});
 
-  tmp = surface (varargin{:});
-
-  ax = get (tmp, "parent");
-
-  set (tmp, "facecolor", "flat");
-  if (! ishold ())
-    set (ax, "view", [-37.5, 30]);
-  endif
+  oldh = gca ();
+  unwind_protect
+    axes (h);
+    newplot ();
+    tmp = surface (varargin{:});
+
+    set (tmp, "facecolor", "flat");
+    if (! ishold ())
+      set (h, "view", [-37.5, 30]);
+    endif
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
 
   if (nargout > 0)
     h = tmp;
--- ./scripts/plot/axes.m.~1.7.~        2007-10-13 06:52:11.000000000 +0200
+++ ./scripts/plot/axes.m       2007-11-28 16:50:59.258102697 +0100
@@ -43,6 +43,9 @@
     ## arg is axes handle, make it the current axes for the current
     ## figure.
     tmp = varargin{1};
+    if (isnan (tmp))
+      tmp = gca ();
+    endif
     if (ishandle (tmp) && strcmp (get (tmp, "type"), "axes"))
       parent = ancestor (tmp, "figure");
       set (0, "currentfigure", parent);
--- ./scripts/plot/meshz.m.~1.2.~       2007-11-28 03:32:42.000000000 +0100
+++ ./scripts/plot/meshz.m      2007-11-28 15:29:27.916617575 +0100
@@ -29,29 +29,7 @@
  
 function retval = meshz (varargin)
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("meshz: expecting first argument to be an axes object");
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (h);
-      tmp = __meshz__ (varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
-    tmp = __meshz__ (varargin{:});
-  endif
-
-  if (nargout > 0)
-    retval = tmp;
-  endif
-
-endfunction
-
-function h = __meshz__ (varargin)
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("meshz", varargin{:});
 
   ioff = nargin + 1;
   for i = 1 : nargin
@@ -95,6 +73,16 @@
        zref .* ones(size(z, 1), 1), z, zref .* ones(size(z, 1), 1); 
        zref.* ones(1, size(z, 2) + 2)];
 
-  h = mesh (x, y, z, varargin{ioff:end});
+  oldh = gca ();
+  unwind_protect
+    axes (h);
+    tmp = mesh (x, y, z, varargin{ioff:end});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
+
+  if (nargout > 0)
+    retval = tmp;
+  endif
 
 endfunction
--- ./scripts/plot/axis.m.~1.45.~       2007-11-15 13:55:07.000000000 +0100
+++ ./scripts/plot/axis.m       2007-11-28 14:48:16.097344233 +0100
@@ -118,31 +118,19 @@
 
 function varargout = axis (varargin)
 
-  if (nargin > 0 && isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("axis: expecting first argument to be an axes object");
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (h);
-      varargout = cell (max (nargin == 1, nargout), 1);
-      if (isempty (varargout))
-       __axis__ (h, varargin{2:end});
-      else
-        [varargout{:}] = __axis__ (h, varargin{2:end});
-      endif
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("axis", varargin{:});
+  oldh = gca ();
+  unwind_protect
+    axes (h);
     varargout = cell (max (nargin == 0, nargout), 1);
     if (isempty (varargout))
-      __axis__ (gca (), varargin{:});
+      __axis__ (h, varargin{:});
     else
-      [varargout{:}] = __axis__ (gca (), varargin{:});
+      [varargout{:}] = __axis__ (h, varargin{:});
     endif
-  endif
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
 
 endfunction
 
--- ./scripts/plot/pie.m.~1.4.~ 2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/pie.m        2007-11-28 16:06:58.970279073 +0100
@@ -44,26 +44,22 @@
 
 function retval = pie (varargin)
 
+  [h, varargin] = __plt_get_axis_arg__ ("pie", varargin{:});
+
   if (nargin < 1)
     print_usage ();
-  elseif (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("pie: expecting first argument to be an axes object");
-    endif
+  else
     oldh = gca ();
     unwind_protect
       axes (h);
       newplot ();
-      tmp = __pie__ (h, varargin{2:end});
+      tmp = __pie__ (h, varargin{:});
     unwind_protect_cleanup
       axes (oldh);
     end_unwind_protect
-  else
-    newplot ();
-    tmp = __pie__ (gca (), varargin{:});
   endif
 
+
   if (nargout > 0)
     retval = tmp;
   endif
--- ./scripts/plot/contour.m.~1.53.~    2007-11-15 10:03:26.000000000 +0100
+++ ./scripts/plot/contour.m    2007-11-28 15:07:47.901985534 +0100
@@ -49,23 +49,15 @@
 
 function [c, h] = contour (varargin)
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("contour: expecting first argument to be an axes object");
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (h);
-      newplot ();
-      [ctmp, htmp] = __contour__ (h, varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
+  [h, varargin] = __plt_get_axis_arg__ ("contour", varargin{:});
+  oldh = gca ();
+  unwind_protect
+    axes (h);
     newplot ();
-    [ctmp, htmp] = __contour__ (gca (), NaN, varargin{:});
-  endif
+    [ctmp, htmp] = __contour__ (h, NaN, varargin{:});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
 
   if (nargout > 0)
     c = ctmp;
--- ./scripts/plot/quiver.m.~1.5.~      2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/quiver.m     2007-11-28 17:10:02.946744283 +0100
@@ -58,24 +58,19 @@
 
 function retval = quiver (varargin)
 
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("quiver", varargin{:});
+
   if (nargin < 2)
     print_usage ();
-  elseif (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("quiver: expecting first argument to be an axes object");
-    endif
+  else
     oldh = gca ();
     unwind_protect
       axes (h);
       newplot ();
-      tmp = __quiver__ (h, 0, varargin{2:end});
+      tmp = __quiver__ (h, 0, varargin{:});
     unwind_protect_cleanup
       axes (oldh);
     end_unwind_protect
-  else
-    newplot ();
-    tmp = __quiver__ (gca (), 0, varargin{:});
   endif
 
   if (nargout > 0)
--- ./scripts/plot/area.m.~1.2.~        2007-11-09 18:56:34.000000000 +0100
+++ ./scripts/plot/area.m       2007-11-28 14:26:10.111052786 +0100
@@ -40,18 +40,13 @@
 
 function h = area (varargin)
 
+  [ax, varargin, nargin] = __plt_get_axis_arg__ ("area", varargin{:});
+
   if (nargin > 0)
     idx = 1;
-    ax = [];
     x = y = [];
     bv = 0;
     args = {};
-    ## Check for axes parent.
-    if (ishandle (varargin{idx})
-       && strcmp (get (varargin{idx}, "type"), "axes"))
-      ax = varargin{idx};
-      idx++;
-    endif
     ## Check for (X) or (X,Y) arguments and possible base value.
     if (nargin >= idx && ismatrix (varargin{idx}))
       y = varargin{idx};
@@ -87,11 +82,13 @@
       x = repmat (x(:),  1, size (y, 2));
     endif
 
-    if (isempty (ax))
-      tmp = __area__ (gca (), x, y, bv, args{:});
-    else
+    oldax = gca ();
+    unwind_protect
+      axes (ax);
       tmp = __area__ (ax, x, y, bv, args{:});
-    endif
+    unwind_protect_cleanup
+      axes (oldax);
+    end_unwind_protect
 
     if (nargout > 0)
       h = tmp;
--- ./scripts/plot/grid.m.~1.38.~       2007-10-13 06:52:11.000000000 +0200
+++ ./scripts/plot/grid.m       2007-11-28 15:27:19.155252292 +0100
@@ -35,31 +35,18 @@
 
 ## PKG_ADD: mark_as_command grid
 
-function grid (x, y)
+function grid (varargin)
 
   persistent grid_on = false;
   persistent minor_on = false;
 
-  nargs = nargin;
-
-  if (nargs == 2)
-    if (ishandle (x))
-      ax = x;
-      x = y;
-      nargs--;
-      if (! strcmp (get (ax, "type"), "axes"))
-       error ("grid: expecting first argument to be an axes object");
-      endif
-    else
-      print_usage ();
-    endif
-  else
-    ax = gca ();
-  endif
-
-  if (nargs == 0)
+  [ax, varargin, nargs] = __plt_get_axis_arg__ ("grid", varargin{:});
+  if (nargs > 1)
+    print_usage ();
+  elseif (nargs == 0)
     grid_on = ! grid_on;
-  elseif (nargs == 1)
+  else
+    x = varargin {1};
     if (ischar (x))
       if (strcmp ("off", x))
        grid_on = false;
@@ -76,8 +63,6 @@
     else
       error ("grid: argument must be a string");
     endif
-  else
-    print_usage ();
   endif
 
   if (grid_on)
--- ./scripts/plot/cylinder.m.~1.3.~    2007-11-26 21:24:47.000000000 +0100
+++ ./scripts/plot/cylinder.m   2007-11-28 15:11:33.533670934 +0100
@@ -45,18 +45,7 @@
 
 function [xx, yy, zz] = cylinder (varargin)
 
-  nargs = nargin;
-  args = varargin;
-  ax = [];
-
-  if (nargs > 0 && isscalar (args{1}) && ishandle (args{1}))
-    if (! strcmp (get (args{1}, "type"), "axes"))
-      error ("cylinder: expecting first argument to be an axes object");
-    endif
-    ax = args{1};
-    nargs--;
-    args(1) = [];
-  endif
+  [ax, args, nargs] = __plt_get_axis_arg__ ("cylinder", varargin{:});
 
   if (nargs == 0)
     n = 20;
@@ -87,10 +76,7 @@
     yy = y;
     zz = z;
   else
-    if (! isempty (ax))
-      axes (ax);
-    endif
-    surf (x, y, z);
+    surf (ax, x, y, z);
   endif
 
 endfunction
--- ./scripts/plot/contour3.m.~1.1.~    2007-11-14 21:36:48.000000000 +0100
+++ ./scripts/plot/contour3.m   2007-11-28 15:02:58.551354456 +0100
@@ -46,27 +46,18 @@
 
 function [c, h] = contour3 (varargin)
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    ax = varargin{1};
-    if (! strcmp (get (ax, "type"), "axes"))
-      error ("contour: expecting first argument to be an axes object");
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (ax);
-      newplot ();
-      [ctmp, htmp] = __contour__ (ax, varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("contour3", varargin{:});
+  oldh = gca ();
+  unwind_protect
+    axes (h);
     newplot ();
-    ax = gca ();
-    [ctmp, htmp] = __contour__ (ax, "level", varargin{:});
-  endif
+    [ctmp, htmp] = __contour__ (h, "level", varargin{:});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
 
   if (! ishold ())
-    set (ax, "view", [-37.5, 30]);
+    set (h, "view", [-37.5, 30]);
   endif
 
   if (nargout > 0)
--- ./scripts/plot/hold.m.~1.6.~        2007-10-13 06:52:11.000000000 +0200
+++ ./scripts/plot/hold.m       2007-11-28 16:52:15.349172238 +0100
@@ -39,7 +39,9 @@
 function hold (varargin)
 
   [h, varargin] = __plt_get_axis_arg__ ("hold", varargin{:});
-
+  if (isnan (h))
+    h = gca ();
+  endif
   hold_state = get (h, "nextplot");
 
   nargs = numel (varargin);
--- ./scripts/plot/surface.m.~1.9.~     2007-11-28 08:31:59.000000000 +0100
+++ ./scripts/plot/surface.m    2007-11-28 16:29:59.475005327 +0100
@@ -41,21 +41,15 @@
 
 function h = surface (varargin)
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("surface: expecting first argument to be an axes object");
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (h);
-      [tmp, bad_usage] = __surface__ (h, varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
-    [tmp, bad_usage] = __surface__ (gca (), varargin{:});
-  endif
+  [h, varargin] = __plt_get_axis_arg__ ("surface", varargin{:});
+
+  oldh = gca ();
+  unwind_protect
+    axes (h);
+    [tmp, bad_usage] = __surface__ (h, varargin{:});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
 
   if (bad_usage)
     print_usage ();
--- ./scripts/plot/patch.m.~1.9.~       2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/patch.m      2007-11-28 16:05:25.324979450 +0100
@@ -36,21 +36,14 @@
 
 function h = patch (varargin)
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes") && ! strcmp (get (h, "type"), 
"hggroup"))
-      error ("patch: expecting first argument to be an axes or hggroup 
object");
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (ancestor (h, "axes"));
-      [tmp, fail] = __patch__ (h, varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
-    [tmp, fail] = __patch__ (gca (), varargin{:});
-  endif
+  [h, varargin] = __plt_get_axis_arg__ ("patch", varargin{:});
+  oldh = gca ();
+  unwind_protect
+    axes (h);
+    [tmp, fail] = __patch__ (h, varargin{:});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
 
   if (fail)
     print_usage ();
--- ./scripts/plot/scatter3.m.~1.2.~    2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/scatter3.m   2007-11-28 16:19:43.087611793 +0100
@@ -55,24 +55,19 @@
 
 function retval = scatter3 (varargin)
 
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("scatter3", varargin{:});
+
   if (nargin < 2)
     print_usage ();
-  elseif (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("scatter3: expecting first argument to be an axes object");
-    endif
+  else
     oldh = gca ();
     unwind_protect
       axes (h);
       newplot ();
-      tmp = __scatter__ (h, 3, "scatter3", varargin{2:end});
+      tmp = __scatter__ (h, 3, "scatter3", varargin{:});
     unwind_protect_cleanup
       axes (oldh);
     end_unwind_protect
-  else
-    newplot ();
-    tmp = __scatter__ (gca (), 3, "scatter3", varargin{:});
   endif
 
   if (! ishold ())
--- ./scripts/plot/plot.m.~1.47.~       2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/plot.m       2007-11-28 16:11:34.687387316 +0100
@@ -178,23 +178,15 @@
 
 function retval = plot (varargin)
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("plot: expecting first argument to be an axes object");
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (h);
-      newplot ();
-      tmp = __plt__ ("plot", h, varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
+  [h, varargin] = __plt_get_axis_arg__ ("plot", varargin{:});
+  oldh = gca ();
+  unwind_protect
+    axes (h);
     newplot ();
-    tmp = __plt__ ("plot", gca (), varargin{:});
-  endif
+    tmp = __plt__ ("plot", h, varargin{:});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
 
   if (nargout > 0)
     retval = tmp;
--- ./scripts/plot/sphere.m.~1.2.~      2007-11-26 22:25:07.000000000 +0100
+++ ./scripts/plot/sphere.m     2007-11-28 16:26:18.589347379 +0100
@@ -29,19 +29,13 @@
 ## @seealso{peaks}
 ## @end deftypefn
 
-function [xx, yy, zz] = sphere (h, n)
+function [xx, yy, zz] = sphere (varargin)
 
-  have_h = false;
-  if (nargin > 1 && isscalar (h) && ishandle (h))
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("sphere: expecting first argument to be an axes object");
-    endif
-    if (nargin == 1)
-      n = 20;
-    endif
-    have_h = true;
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("sphere", varargin{:});
+  if (nargin > 1)
+    print_usage ();
   elseif (nargin == 1)
-    n = h;
+    n = varargin {1};
   else
     n = 20;
   endif
@@ -59,17 +53,7 @@
     yy = y;
     zz = z;
   else
-    if (have_h)
-      oldh = gca ();
-      unwind_protect
-       axes (h);
-       surf (x, y, z);
-      unwind_protect_cleanup
-       axes (oldh);
-      end_unwind_protect
-    else
-      surf (x, y, z);
-    endif
+    surf (h, x, y, z);
   endif
 
 endfunction
--- ./scripts/plot/polar.m.~1.37.~      2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/polar.m      2007-11-28 17:09:06.124644261 +0100
@@ -30,7 +30,7 @@
 
 function retval = polar (varargin)
 
-  [h, varargin] = __plt_get_axis_arg__ ("loglogerr", varargin{:});
+  [h, varargin] = __plt_get_axis_arg__ ("polar", varargin{:});
   oldh = gca ();
   unwind_protect
     axes (h);
--- ./scripts/plot/quiver3.m.~1.2.~     2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/quiver3.m    2007-11-28 16:16:42.472796712 +0100
@@ -61,24 +61,19 @@
 
 function retval = quiver3 (varargin)
 
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("quiver3", varargin{:});
+
   if (nargin < 2)
     print_usage ();
-  elseif (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("quiver: expecting first argument to be an axes object");
-    endif
+  else
     oldh = gca ();
     unwind_protect
       axes (h);
       newplot ();
-      tmp = __quiver__ (h, 1, varargin{2:end});
+      tmp = __quiver__ (h, 1, varargin{:});
     unwind_protect_cleanup
       axes (oldh);
     end_unwind_protect
-  else
-    newplot ();
-    tmp = __quiver__ (gca (), 1, varargin{:});
   endif
 
   if (nargout > 0)
--- ./scripts/plot/plotyy.m.~1.4.~      2007-11-28 08:30:06.000000000 +0100
+++ ./scripts/plot/plotyy.m     2007-11-28 16:13:50.784503534 +0100
@@ -55,29 +55,19 @@
 
 function [Ax, H1, H2] = plotyy (varargin)
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    ax = varargin{1};
-    if (! strcmp (get (ax, "type"), "axes"))
-      error ("plotyy: expecting first argument to be an axes object");
-    endif
-    if (nargin < 5)
-      print_usage ();
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (ax);
-      newplot ();
-      [ax, h1, h2] = __plotyy__ (ax, varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
-    if (nargin < 4)
-      print_usage ();
-    endif
-    newplot ();
-    [ax, h1, h2] = __plotyy__ (gca (), varargin{:});
+  [ax, varargin] = __plt_get_axis_arg__ ("plotyy", varargin{:});
+
+  if (nargin < 4)
+    print_usage ();
   endif
+  oldh = gca ();
+  unwind_protect
+    axes (ax);
+    newplot ();
+    [ax, h1, h2] = __plotyy__ (ax, varargin{:});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
 
   if (nargout > 0)
     Ax = ax;
--- ./scripts/plot/xlabel.m.~1.31.~     2007-11-28 08:30:07.000000000 +0100
+++ ./scripts/plot/xlabel.m     2007-11-28 16:56:41.863522508 +0100
@@ -30,32 +30,24 @@
 
 ## Author: jwe
 
-function h = xlabel (varargin)
+function retval = xlabel (varargin)
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    ax = varargin{1};
-    if (! strcmp (get (ax, "type"), "axes"))
-      error ("xlabel: expecting first argument to be an axes object");
-    endif
-    if (rem (nargin, 2) == 1)
-      print_usage ();
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (ax);
-      tmp = __axis_label__ ("xlabel", varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
-    if (rem (nargin, 2) != 1)
-      print_usage ();
-    endif
-    tmp = __axis_label__ ("xlabel", varargin{1:end});
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("xlabel", varargin{:});
+
+  if (rem (nargin, 2) != 1)
+    print_usage ();
   endif
 
+  oldh = gca ();
+  unwind_protect
+    axes (h);
+    tmp = __axis_label__ ("xlabel", varargin{:});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
+
   if (nargout > 0)
-    h = tmp;
+    retval = h;
   endif
 
 endfunction
--- ./scripts/plot/ylabel.m.~1.26.~     2007-11-28 08:30:07.000000000 +0100
+++ ./scripts/plot/ylabel.m     2007-11-28 16:57:25.661299271 +0100
@@ -25,32 +25,24 @@
 
 ## Author: jwe
 
-function h = ylabel (varargin)
+function retval = ylabel (varargin)
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    ax = varargin{1};
-    if (! strcmp (get (ax, "type"), "axes"))
-      error ("ylabel: expecting first argument to be an axes object");
-    endif
-    if (rem (nargin, 2) == 1)
-      print_usage ();
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (ax);
-      tmp = __axis_label__ ("ylabel", varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
-    if (rem (nargin, 2) != 1)
-      print_usage ();
-    endif
-    tmp = __axis_label__ ("ylabel", varargin{1:end});
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("ylabel", varargin{:});
+
+  if (rem (nargin, 2) != 1)
+    print_usage ();
   endif
 
+  oldh = gca ();
+  unwind_protect
+    axes (h);
+    tmp = __axis_label__ ("ylabel", varargin{:});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
+
   if (nargout > 0)
-    h = tmp;
+    retval = h;
   endif
 
 endfunction
--- ./scripts/plot/surfnorm.m.~1.3.~    2007-11-28 08:30:07.000000000 +0100
+++ ./scripts/plot/surfnorm.m   2007-11-28 16:43:24.688560422 +0100
@@ -51,31 +51,23 @@
 
 function varargout = surfnorm (varargin)
 
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("surfnorm", varargin{:});
+
+  if (nargin != 1 && nargin != 3)
+    print_usage ();
+  endif
+
   if (nargout > 0)
     varargout = cell (nargout, 1);
+    [varargout{:}] = __surfnorm__ (h, varargin{:});
   else
-    varargout = cell (0, 0);
-  endif
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    h = varargin{1};
-    if (! strcmp (get (h, "type"), "axes"))
-      error ("surfnorm: expecting first argument to be an axes object");
-    endif
-    if (nargin != 2 && nargin != 4)
-      print_usage ();
-    endif
     oldh = gca ();
     unwind_protect
       axes (h);
-      [varargout{:}] = __surfnorm__ (h, varargin{2:end});
+      __surfnorm__ (h, varargin{:});
     unwind_protect_cleanup
       axes (oldh);
     end_unwind_protect
-  else
-    if (nargin != 1 && nargin != 3)
-      print_usage ();
-    endif
-    [varargout{:}] = __surfnorm__ (gca (), varargin{:});
   endif
 
 endfunction
--- ./scripts/plot/zlabel.m.~1.22.~     2007-11-28 08:30:07.000000000 +0100
+++ ./scripts/plot/zlabel.m     2007-11-28 16:57:48.083160812 +0100
@@ -25,32 +25,24 @@
 
 ## Author: jwe
 
-function h = zlabel (varargin)
+function retval = zlabel (varargin)
 
-  if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    ax = varargin{1};
-    if (! strcmp (get (ax, "type"), "axes"))
-      error ("zlabel: expecting first argument to be an axes object");
-    endif
-    if (rem (nargin, 2) == 1)
-      print_usage ();
-    endif
-    oldh = gca ();
-    unwind_protect
-      axes (ax);
-      tmp = __axis_label__ ("zlabel", varargin{2:end});
-    unwind_protect_cleanup
-      axes (oldh);
-    end_unwind_protect
-  else
-    if (rem (nargin, 2) != 1)
-      print_usage ();
-    endif
-    tmp = __axis_label__ ("zlabel", varargin{1:end});
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("zlabel", varargin{:});
+
+  if (rem (nargin, 2) != 1)
+    print_usage ();
   endif
 
+  oldh = gca ();
+  unwind_protect
+    axes (h);
+    tmp = __axis_label__ ("zlabel", varargin{:});
+  unwind_protect_cleanup
+    axes (oldh);
+  end_unwind_protect
+
   if (nargout > 0)
-    h = tmp;
+    retval = h;
   endif
 
 endfunction
2007-11-28  David Bateman  <address@hidden>

        * __plt_get_axis_handle__.m: Also allow hggroup and return axes
        ancestor. If no axis handle found return NaN to prevent immediate
        display of a figure.
        * hold.m: __plt__get_axis_handle__ now returns NaN rather than
        gca() is no handle found. Adapt hold function.
        * axes.m: Accept NaN as a valid axis handle and call gca() in this
        case.
        * __bar__.m, caxis.m, scatter.m, contourf.m, __axes_limits__.m,
        fill.m,  surf.m, meshz.m, axis.m, pie.m, contour.m,
        quiver.m, area.m, grid.m, cylinder.m, contour3.m, surface.m,
        patch.m, scatter3.m, plot.m, sphere.m, quiver3.m, plotyy.m,
        xlabel.m, ylabel.m, surfnorm.m, zlabel.m: Adapt to use
        __plt__get_axis_arg__ to find axis handle.
        * polar.m: Typo.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]