12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby の gnuplot wrapper 経由で gnuplot を利用し、折れ線グラフを描画する

Posted at

:musical_score: 概要

Ruby の gnuplot wrapper 経由で gnuplot を利用し、折れ線グラフを描画する

:musical_note: 前提

  • OS: Windows7
  • gnuplot: version 4.6

:scroll: 手順

gnuplot windows 64 bit 版のインストール

下記ページの

gp466-win64-setup.exe

をダウンロードし、 gnuplot のインストーラーを実行します。
ウィザードに従ってインストール後, 下記コマンドでインストールの確認をします。

% gnuplot --version
gnuplot 4.6 patchlevel 6

Ruby の gnuplot wrapper をインストールする

% gem install gnuplot

サンプル

折れ線グラフを作成します

ソースコード

require "gnuplot"

Gnuplot.open do |gp|
  Gnuplot::Plot.new( gp ) do |plot|
    plot.title  "Array Plot Example"
    plot.xlabel "x"
    plot.ylabel "y"
    plot.yrange "[0:5000]"
    
    x = (0..50).map(&:to_f)
    y = x.map{ |v| (v ** 2) + 3000 }
    x2 = (0..50).map(&:to_f)
    y2 = x.map{ |v| 2*v ** 2 + 2500 }

    plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
      ds.with = "lines"
      ds.linewidth = 2
    end
    plot.data << Gnuplot::DataSet.new( [x2, y2] ) do |ds|
      ds.with = "lines"
      ds.linewidth = 2
    end
  end
end

実行結果

gnuplot_sample.png

:books: 外部資料

12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?