Unlike plot(), when I want to change xdata and ydata in a stem (or stairs), I
have to issue set(hs,'xdata'...) two times.
A clumsy solution is the try..catch statement. The following snippet works
fine in Octave 3.6.4 VS2010 with fltk.
hf= figure;
N = 20;
x = 0:(N-1);
y = rand(1,N);
hs=stem(x(1),y(1));
% hs=stairs(x(1),y(1));
% hs=plot(x(1),y(1));
set(gca(), 'xlim',[1,N], 'ylim',[0,1]);
for k=2:N
pause(0.2);
try
set(hs, 'xdata',x(1:k), 'ydata', y(1:k));
catch
set(hs, 'xdata',x(1:k), 'ydata', y(1:k));
printf("catch at k= %d\n", k);
end_try_catch
drawnow();
endfor
I see that stem has type=hggroup with 2 children, while plot has type=line.
So I figured that the problem arises because the command set(hs,'xdata'...)
is actually fixing one child at time. Is that right?
Anyway I have to say that it would be more convenient if a single set()
command took care of these details automatically. Don't you think?