Octave plot points as animation

与世无争的帅哥 提交于 2019-12-05 13:38:01

Try adding drawnow at the end of the iteration. At least that works in Matlab. It forces the interpreter to empty the graphic event queue.

If you include pause at the end of the iteration, drawnow may not be needed (pause already empties the event queue). But I usually add it just in case.

Other comments:

  • You don't need hold on at every iteration. It sufficies to do it once, at the beginning.
  • You may want to freeze the axis to prevent auto-scaling when a new point is added

With these modifications, your code would become:

TOTAL_POINTS = 100;
figure(1)
hold on; 
axis([0 1 0 1]) %// set axis
axis manual %// prevent axis from auto-scaling
for i=1:TOTAL_POINTS
   randX = rand(1); 
   randY = rand(1);
   scatter(randX, randY);
   pause(.1) %// pause 0.1 seconds to slow things down
   drawnow
endfor
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!