Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created July 12, 2015 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/27e65a70d4681dd73370 to your computer and use it in GitHub Desktop.
Save komasaru/27e65a70d4681dd73370 to your computer and use it in GitHub Desktop.
Ruby script to draw a graph by gnuplot.(Ex.2)
#! /usr/local/bin/ruby
#-----------------------------------------------
# Ruby script to draw a graph by gnuplot.(Ex.2)
#-----------------------------------------------
require 'gnuplot'
Gnuplot.open do |gp|
Gnuplot::Plot.new(gp) do |plot|
plot.terminal "png enhanced font 'IPA P ゴシック' fontscale 1.2"
plot.output "gnuplot_2.png"
plot.title "作成例2"
plot.xlabel "x"
plot.ylabel "y=x^3-2x+2"
plot.grid
x = (-20..20).collect { |v| v.to_f / 10.0 }
y = x.collect { |v| v ** 3 - 2 * v + 2}
plot.data << Gnuplot::DataSet.new([x, y]) do |ds|
ds.with = "linespoints" # 点のみなら "points"
ds.linewidth = 2
ds.linecolor = 3
ds.notitle
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment