Created
July 12, 2015 04:48
-
-
Save komasaru/27e65a70d4681dd73370 to your computer and use it in GitHub Desktop.
Ruby script to draw a graph by gnuplot.(Ex.2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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