Ruby Gnuplotでプロットしたデータの凡例を設定する

Ruby Gnuplot複数データをプロットする場合凡例をつけたかったのだか、
なんだかよくわからなかったので、
凡例を設定したい場合どうすれば良いのか調べたまとめ
まずRuby Gnuplotでグラフを作成する場合このようになる

Gnuplot.open do |gp|
  Gnuplot::Plot.new( gp ) do |plot|
  
    plot.title  "Array Plot Example"
    plot.xlabel "x"
    plot.ylabel "x^2"
    
    x = (0..50).collect { |v| v.to_f }
    y = x.collect { |v| v ** 2 }

    plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
      ds.with = "linespoints"
      ds.notitle
    end
  end
end
https://github.com/rdp/ruby_gnuplot

これではds.notitleによって凡例を付けない設定になってしまう
Gnuplotでは凡例をつけようという場合、plot abs(x) title "|x|"のようにplotのコマンドに併記する形でタイトルをつけるが、
RubyGnuplotではds(DataSetクラス)にds.titleという変数があるので表示したい凡例を代入するとよい

File.open( "gnuplot.dat", "w") do |gp|
  Gnuplot::Plot.new( gp ) do |plot|
  
    plot.xrange "[-10:10]"
    plot.title  "Sin Wave Example"
    plot.ylabel "x"
    plot.xlabel "sin(x)"
    
    x = (0..50).collect { |v| v.to_f }
    y = x.collect { |v| v ** 2 }

    plot.data = [
      Gnuplot::DataSet.new( "sin(x)" ) { |ds|
        ds.with = "lines"
        ds.title = "String function"
    	  ds.linewidth = 4
      },
    
      Gnuplot::DataSet.new( [x, y] ) { |ds|
        ds.with = "linespoints"
        ds.title = "Array data"
      }
    ]

  end
end
https://github.com/rdp/ruby_gnuplot

ただ代入するだけで凡例を変えることができる
なんだか混乱して、ds.set "title 'x'"とかds.tilte "x"とかに間違えてしまった