2013-05-03 132 views
2

我想用gnuplot gem绘制一个XY坐标线bord,但是当运行我的代码时它会自动关闭它。我一直在检查这个例子,我想我做的一切正常,任何人都可以帮助我让我的gnuplot窗口更明显吗?我一直在尝试睡眠,但无法弄清楚,为什么它仍然失败。管道程序窗口立即关闭

Gnuplot.open do |gp| 
    # Start a new plot 
    Gnuplot::Plot.new(gp) do |plot| 
     plot.title fn 
     # plot.grid 

     # Plot each cluster's points 
     clusters.each do |cluster| 
     # Collect all x and y coords for this cluster 
     x = cluster.points.collect {|p| p.x } 
     y = cluster.points.collect {|p| p.y } 

     # Plot w/o a title (clutters things up) 
     plot.data << Gnuplot::DataSet.new([x,y]) do |ds| 
      ds.notitle 
     end 
     end 
    end 
    end 
+3

我不知道这个红宝石界面,但它看起来像你想要的是能够将'-p'或'--persist'选项传递给gnuplot。搜索文档以了解如何做到这一点。 – andyras 2013-05-03 17:00:42

+1

你使用Windows吗?在Windows上,只要管道关闭,即使使用'--persist'选项,gnuplot也会关闭。我认为这是因为Windows缺少'fork'。解决方法是让程序在退出前等待击键。在Linux上,gnuplot应该完全有能力(通过'--persist')在管道关闭后保持窗口打开。 – 2013-05-04 12:39:23

+0

谢谢,我用windows。作为一个修复我搬到.gif输出...不是最好的解决方案,但在这一点上,它是最好的。 – 2013-05-05 18:03:41

回答

0

,因为没有的answere已经公布,我会把我所用的方法:输出到图片格式:

# Graph output by running gnuplot pipe 
    Gnuplot.open do |gp| 
    # Start a new plot 
    Gnuplot::Plot.new(gp) do |plot| 
     plot.title fn 
     # plot.grid 


    plot.terminal "gif" 
    plot.output File.expand_path("../test.gif", __FILE__) 

     # Plot each cluster's points 
     clusters.each do |cluster| 
     # Collect all x and y coords for this cluster 
     x = cluster.points.collect {|p| p.x } 
     y = cluster.points.collect {|p| p.y } 

     # Plot w/o a title (clutters things up) 
     plot.data << Gnuplot::DataSet.new([x,y]) do |ds| 
      ds.notitle 
     end 
     end 
    end 
    end 
0

你尝试暂停命令?在本地gnuplot暂停-1等待用户按Enter键。