Octave plot points as animation

若如初见. 提交于 2019-12-22 08:37:34

问题


I have the following octave script,

TOTAL_POINTS = 100;
figure(1)

for i=1:TOTAL_POINTS
   randX = rand(1); 
   randY = rand(1);

   scatter(randX, randY);
   hold on; 
endfor

When I run this by octave script.m, I get nothing. When I add the line pause to the end of this script, it works but I only see the plot after all the 100 points are plotted.

I want to see the plot point by point. Not after I plotted every single point.

PS: I have Ubuntu.


回答1:


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


来源:https://stackoverflow.com/questions/24207286/octave-plot-points-as-animation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!