Last active
October 6, 2021 14:50
-
-
Save yuasatakayuki/94d48604e1609fb3418e2628e8f2032d to your computer and use it in GitHub Desktop.
Plot time-series data using Ruby Gnuplot
This file contains hidden or 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
require "gnuplot" | |
data=<<EOS | |
2016-07-19T23:47:53.432Z 33.2 | |
2016-07-19T23:41:59.558Z 33.1 | |
2016-07-19T23:36:06.183Z 32.9 | |
2016-07-19T23:30:09.101Z 32.7 | |
2016-07-19T23:24:15.936Z 32.6 | |
2016-07-19T23:18:19.082Z 32.4 | |
2016-07-19T23:12:20.944Z 32.4 | |
2016-07-19T23:06:28.191Z 32.3 | |
2016-07-19T23:00:35.459Z 31.6 | |
2016-07-19T22:54:33.798Z 31.2 | |
2016-07-19T22:48:31.436Z 30.7 | |
2016-07-19T22:42:27.744Z 30.1 | |
2016-07-19T22:36:30.776Z 29.7 | |
2016-07-19T22:30:32.814Z 29.4 | |
2016-07-19T22:24:38.774Z 28.8 | |
2016-07-19T22:18:38.911Z 28.5 | |
2016-07-19T22:12:45.805Z 28.2 | |
2016-07-19T22:06:39.124Z 27.7 | |
2016-07-19T22:00:39.920Z 27.1 | |
2016-07-19T21:54:42.007Z 26.5 | |
EOS | |
x = [] | |
y = [] | |
data.lines(){|line| | |
a=line.split() | |
x << a[0] | |
y << a[1] | |
} | |
Gnuplot.open() do |gp| | |
Gnuplot::Plot.new( gp ) do |plot| | |
plot.ylabel 'Temperature degree' | |
plot.xlabel "Time (starting at #{x[0]})" | |
plot.timefmt "'%Y-%m-%dT%H:%M:%SZ'" | |
plot.xdata "time" | |
plot.format "x '%H:%M'" | |
plot.style "data lines" | |
plot.set 'terminal postscript color eps enhanced font "Helvetica,13" size 16cm,8cm' | |
plot.set "output 'temperature-pcb.ps'" | |
plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds| | |
ds.with = "linespoints" | |
ds.linecolor = "black" | |
ds.linewidth = "3" | |
ds.notitle | |
ds.using = "1:2" | |
end | |
end | |
end | |
`ps2pdf temperature-pcb.ps` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment