diff scripts/plot/__patch__.m @ 6885:987a7bf45c99

[project @ 2007-09-10 20:51:09 by jwe]
author jwe
date Mon, 10 Sep 2007 20:51:09 +0000
parents 0089a504fdd6
children 1c1d62569590
line wrap: on
line diff
--- a/scripts/plot/__patch__.m
+++ b/scripts/plot/__patch__.m
@@ -27,77 +27,120 @@
 
 function h = __patch__ (p, varargin)
 
-  if (nargin < 1)
+  if (nargin < 3)
+    print_usage ();
+  endif
+
+  iarg = 1;
+  have_x = have_z = have_c = false;
+  if (isnumeric (varargin {1}))
+    if (!isnumeric (varargin {2}))
+      print_usage ();
+    endif
+
+    x = varargin {1};
+    y = varargin {2};
+    have_x = true;
+    iarg += 2;
+
+    if (nargin > 3 && ndims (varargin {3}) == 2 && 
+	size (varargin {3}) == size (x))
+      z = varargin {3};
+      have_z = true;
+      iarg ++;
+    endif
+  endif
+
+  if (have_x && nargin > iarg && isnumeric (varargin {iarg}))
+    c = varargin {iarg};
+    have_c = true;
+    iarg ++;
+
+    if (ndims (c) == 3 && size (c, 2) == 1)
+      c = permute (c, [1, 3, 2]);
+    endif
+  endif
+
+  if (rem (nargin - iarg, 2) != 0)
     print_usage ();
   endif
 
-  nvargs = numel (varargin);
-
-  if (nvargs > 1 && isnumeric (varargin{1}) && isnumeric (varargin{2}))
-    num_data_args = 2;
-  else
-    num_data_args = 0;
-  endif
+  if (have_x)
+    if (isvector (x))
+      x = x(:);
+      y = y(:);
+      if (have_z)
+	z = z(:);
+      endif
+    endif
 
-  if (rem (nvargs - num_data_args - 1, 2) == 0 && nvargs > 2)
-  else
-    print_usage ("patch");
-  endif
-
-  x = varargin{1};
-  y = varargin{2};
-  c = varargin{3};
+    [nr, nc] = size (x);
 
-  h = __go_patch__ (p);
-  ax = get (h, "parent");
-  if (num_data_args > 1)
-    set (h, "xdata", x, "ydata", y);
-  endif
+    for i = 1 : nc
+      h = __go_patch__ (p);
+      ax = get (h, "parent");
+      if (have_x)
+	set (h, "xdata", x (:, i), "ydata", y (:, i));
+	if (have_z)
+	  set (h, "zdata", z (:, i));
+	endif
+      endif
 
-  if (isstr (c))
-    ## Have color string.
-    set (h, "FaceColor", c);
-  elseif (length (c) == 1)
-    if (isnan (c))
-      set (h, "FaceColor", [1, 1, 1]);
-      set (h, "CData", c);
-    elseif (isnumeric (c))
-      ## Have color index.
-      set (h, "FaceColor", "flat");
-      set (h, "CData", c);
+      if (have_c)
+	if (ndims (c) == 2 && ((nr > 3 && size (c, 2) == nc) ||
+			       (size (c, 1) > 1 && size (c, 2) == nc)))
+	  c2 = c (:, i);
+	elseif (ndims (c) == 3)
+	  c2 = permute (c (:, i, :), [1, 3, 2]);
+	else
+	  c2 = c;
+	endif
 
-      clim = get(ax, "CLim");
-      if (c < clim(1))
-        set (ax, "CLim", [c, clim(2)])
+	if (numel (c2) == 1)
+	  if (isnan (c))
+	    set (h, "FaceColor", [1, 1, 1]);
+	    set (h, "CData", c2);
+	  elseif (isnumeric (c2))
+	    ## Have color index.
+	    set (h, "FaceColor", "flat");
+	    set (h, "CData", c2);
+	    clim = get(ax, "CLim");
+	    if (c2 < clim(1))
+              set (ax, "CLim", [c2, clim(2)])
+	    endif
+	    if (c2 > clim(2))
+              set (ax, "CLim", [clim(1), c2])
+	    endif
+	  else
+	    ## Unknown color value.
+	    error ("color value not valid");
+	  endif
+	elseif (numel (c2) == 3)
+	  ## Have rgb/rgba value.
+	  set (h, "FaceColor", c2);
+	else
+	  ## Color vector.
+	  if (length (c2) != length (x) || length (c2) != length (y))
+	    error ("size of x, y, and c must be equal")
+	  else
+	    set (h, "FaceColor", "interp");
+	    set(h, "CData", c2);
+	    if (abs(max(c2) - min(c2)) < eps)
+              set (ax, "CLim", [c2(1)-1, c2(1)+1])
+	    else
+              set (ax, "CLim", [min(c2), max(c2)]);
+	    endif
+	  endif
+	endif
+      else
+	set (h, "FaceColor", [0, 1, 0]);
       endif
-      if (c > clim(2))
-        set (ax, "CLim", [clim(1), c])
-      end
 
-    else
-      ## Unknown color value.
-      error ("color value not valid");
-    end
-  elseif (length (c) == 3)
-    ## Have rgb/rgba value.
-    set (h, "FaceColor", c);
+      if (nargin > iarg + 1)
+	set (h, varargin{iarg:end});
+      endif
+    endfor
   else
-    ## Color vector.
-    if (length (c) != length (x) || length (c) != length (y))
-      error ("size of x, y, and c must be equal")
-    else
-      set (h, "FaceColor", "interp");
-      set(h, "CData", c);
-      if (abs(max(c) - min(c)) < eps)
-        set (ax, "CLim", [c(1)-1, c(1)+1])
-      else
-        set (ax, "CLim", [min(c), max(c)]);
-      end
-    end
-  end 
-
-  if (nvargs > num_data_args + 1)
-    set (h, varargin{num_data_args+2:end});
+    error ("Not supported");
   endif
-
 endfunction