【问题标题】:Octave plot points as animation八度绘图点作为动画
【发布时间】:2014-06-13 14:05:15
【问题描述】:

我有以下八度脚本,

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 点后才能看到该图。

我想逐点看情节。不是在我绘制了每一个点之后。

PS:我有Ubuntu

【问题讨论】:

    标签: matlab plot octave


    【解决方案1】:

    尝试在迭代结束时添加drawnow。至少这在 Matlab 中有效。它强制解释器清空图形事件队列。

    如果您在迭代结束时包含pause,则可能不需要drawnowpause 已清空事件队列)。但我通常会添加它以防万一。

    其他cmets:

    • 您不需要在每次迭代中使用hold on。一开始就做一次就足够了。
    • 您可能希望在添加新点时冻结轴以防止自动缩放

    通过这些修改,您的代码将变为:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多