八度绘图点作为动画 [英] Octave plot points as animation
问题描述
我有以下八度音阶脚本,
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
当我用octave script.m
运行它时,我什么也没得到.当我将pause
行添加到此脚本的末尾时,它可以工作,但是我只在绘制所有100
点之后才能看到该图.
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:我有Ubuntu
.
推荐答案
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.
如果在迭代末尾包含pause
,则可能不需要drawnow
(pause
已清空事件队列).但是我通常会添加它,以防万一.
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.
其他评论:
- 您不需要每次迭代都使用
hold on
.一开始就做一次就足够了. - 您可能希望冻结轴以防止在添加新点时自动缩放
- 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
这篇关于八度绘图点作为动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!