Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.