changeset 16751:92811d110839

Update copies consistent subset of {x,y,z}data to children of the stem hggoup. (Bug # 39234) * scripts/plot/stem.m: Add demo. * scripts/plot/private/__stem__.m: When a listener triggers an update copy {x,y,z}data(1:M,1:N) to the hggroup's children, where M/N are the minimum number of rows/columns among the matrices, {x,y,z}data.
author Ben Abbott <bpabbott@mac.com>
date Wed, 12 Jun 2013 20:06:18 +0800
parents fd5a4b7f59f7
children d6b666e8449c
files scripts/plot/private/__stem__.m scripts/plot/stem.m
diffstat 2 files changed, 37 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/private/__stem__.m	Tue Jun 11 21:16:41 2013 +0800
+++ b/scripts/plot/private/__stem__.m	Wed Jun 12 20:06:18 2013 +0800
@@ -531,27 +531,31 @@
   z = get (h, "zdata");
 
   if (!isempty (z) && size_equal (x, y, z))
-    error ("stem3: inconsistent size of x, y and z");
-  elseif (numel (x) != numel (y))
-    error ("stem: inconsistent size of x and y");
+    sz = min ([size(x); size(y); size(z)]);
+    x = x(1:sz(1),1:sz(2));
+    y = y(1:sz(1),1:sz(2));
+    z = z(1:sz(1),1:sz(2));
+  elseif (numel (x) != numel (y));
+    sz = min ([size(x); size(y)]);
+    x = x(1:sz(1),1:sz(2));
+    y = y(1:sz(1),1:sz(2));
+  endif
+  bl = get (h, "basevalue");
+  nx = numel (x);
+  x = x(:)';
+  xt = [x; x; NaN(1, nx)](:);
+  if (! isempty (z))
+    y = y(:)';
+    yt = [y; y; NaN(1, nx)](:);
+    z = z(:)';
+    zt = [bl * ones(1, nx); z; NaN(1, nx)](:);
   else
-    bl = get (h, "basevalue");
-    nx = numel (x);
-    x = x(:)';
-    xt = [x; x; NaN(1, nx)](:);
-    if (! isempty (z))
-      y = y(:)';
-      yt = [y; y; NaN(1, nx)](:);
-      z = z(:)';
-      zt = [bl * ones(1, nx); z; NaN(1, nx)](:);
-    else
-      y = y(:)';
-      yt = [bl * ones(1, nx); y; NaN(1, nx)](:);
-      zt = [];
-    endif
+    y = y(:)';
+    yt = [bl * ones(1, nx); y; NaN(1, nx)](:);
+    zt = [];
+  endif
 
-    kids = get (h, "children");
-    set (kids(2), "xdata", xt, "ydata", yt, "zdata", zt);
-    set (kids(1), "xdata", x, "ydata", y, "zdata", z);
-  endif
+  kids = get (h, "children");
+  set (kids(2), "xdata", xt, "ydata", yt, "zdata", zt);
+  set (kids(1), "xdata", x, "ydata", y, "zdata", z);
 endfunction
--- a/scripts/plot/stem.m	Tue Jun 11 21:16:41 2013 +0800
+++ b/scripts/plot/stem.m	Wed Jun 12 20:06:18 2013 +0800
@@ -130,3 +130,15 @@
 %! set (h(2), 'color', 'g');
 %! set (h(1), 'basevalue', -1);
 
+%!demo
+%! clf;
+%! N = 11;
+%! x = 0:(N-1);
+%! y = rand (1, N);
+%! hs = stem (x(1), y(1));
+%! set (gca (), 'xlim', [1, N-1], 'ylim', [0, 1]);
+%! for k=2:N
+%!   set (hs, 'xdata', x(1:k), 'ydata', y(1:k))
+%!   drawnow ();
+%!   pause (0.2);
+%! end