Skip to content

Instantly share code, notes, and snippets.

@jzrake
Created February 2, 2012 02:46
Show Gist options
  • Save jzrake/1721079 to your computer and use it in GitHub Desktop.
Save jzrake/1721079 to your computer and use it in GitHub Desktop.
Calling gnuplot from Lua
local function plot(series, tpause)
local gp = io.popen("gnuplot", 'w')
local lines = { }
for k,v in pairs(series) do
table.insert(lines, string.format(" '-' u 1:2 title '%s'", k))
end
gp:write("plot" .. table.concat(lines, ",") .. "\n")
for k,v in pairs(series) do
for i=1,#v do
gp:write(string.format("%f %f\n", i, v[i]))
end
gp:write("e\n")
end
gp:write(string.format("pause %f\n", tpause or 100.0))
gp:close()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment