雑多な技術系メモ

自分用のメモ。内容は保証しません。よろしくお願いします。

3Dグラフ用のサンプルプログラム

rubygnuplotで3Dグラフを生成するサンプルを貼っておきます。

require "gnuplot"

Gnuplot.open do |gp|
  Gnuplot::SPlot.new( gp ) do |plot|
    plot.output "test.eps"
    plot.xlabel "x"
    plot.ylabel "y" 
    plot.zlabel "z" 
    plot.set 'terminal postscript 16 eps enhanced color '
    plot.set "dgrid3d"
    plot.grid

    x = Array.new
    y = Array.new
    z = Array.new
    10.times do |num|
      x.push(num)
      y.push(num)
      z.push(num)
    end

    plot.data << Gnuplot::DataSet.new( [x, y, z] ) do |ds|
      ds.with = "p"  ;  
      ds.title = "test";
    end
  end
end