ug4
GNUPlot Utility

Functions

function gnuplot available_terminals ()
 
function gnuplot plot (filename, data, options)
 

Detailed Description

create a globally seen package (all non-local functions call then be called using gnuplot.xxx.)

Function Documentation

◆ available_terminals()

function gnuplot available_terminals ( )

list of all available terminals

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / gnuplot.lua :44-58

function gnuplot.available_terminals()
if not gnuplot.terminals then
gnuplot.terminals = {}
local termFile = os.tmpname()
os.execute("echo | gnuplot -e 'set terminal' &> "..termFile)
for line in io.lines(termFile) do
line = string.gsub (line, "Press return for more:", "")
table.insert(gnuplot.terminals, string.match (line, "%s+(%w*)%s+"))
end
os.remove(termFile)
end
return gnuplot.terminals
end
int local(bglp_vertex_descriptor p)
Definition: parallel_matrix.h:57

References close(), func(), ug::detail::local(), pcl::ProcRank(), and write().

◆ plot()

function gnuplot plot ( filename  ,
data  ,
options   
)

filename the output file data table containing the data passRows flag indication if data array stores rows (default = false) ]] function gnuplot.write_data(filename, data, passRows, mode)

– default is table data by row passRows = passRows or false mode = mode or "w+" forNil = "--"

– check data if type(data) ~= "table" then write("Gnuplot Error: Expect table as data.\n"); return 1
end if data[1]==nil then return 0; end

– pure data is rowwise if type(data[1]) == "number" then passRows = true end

– only root proc writes data if ProcRank() ~= 0 then return 0 end

– open file local file = io.open(filename, mode) if (not file) then write("Gnuplot Error: cannot open output file: '") write(filename .. " '\n"); return 1 end

– case 1: data is given column per column if not passRows then

– check columns local bHasMatrixData = false local minRow = math.huge local maxRow = -math.huge for _, column in ipairs(data) do

– check that tables passed as coulumns if not(type(column) == "table") then write("Gnuplot Error: Data array must contain only tables.\n"); return 1
end

– check if column data is actually a matrix
– or extract row range
if type(column[1]) == "table" then bHasMatrixData = true
else minRow = math.min(minRow, table.imin(column)) maxRow = math.max(maxRow, table.imax(column))
end end

– write column if not(bHasMatrixData) then for row = minRow, maxRow do for col, _ in ipairs(data) do local item = data[col][row] if item ~= nil then file:write(item, " ") else file:write(forNil, " ") end end file:write("\n") end
else if type(data[1][1]) == "table" or type(data[2][1]) == "table" then write("Gnuplot: Format for matrix data: x, y, data"); return 1
end
for i = 3,#data do if type(data[i][1]) ~= "table" then write("Gnuplot: Format for matrix data: x, y, data"); return 1
end
end

for i = 1, #data[1] do for j = 1, #data[2] do file:write(data[1][i], " ", data[2][j], " ")
for k = 3,#data do file:write(data[k][i][j], " ")
end file:write("\n") end file:write("\n") end end

– case 2: data is given column per column else local plainArray, rowSize

for i, item in ipairs(data) do if type(item) == "table" then – check for pure tables if plainArray == nil then plainArray = false elseif plainArray == true then write("Gnuplot Error: Data array mixes tables and numbers.\n"); return 1
end

– check number data items in Row if rowSize == nil then rowSize = #item elseif not (rowSize == #item) then write("Gnuplot Error: Data array of mixed sized rows.\n"); return 1
end

– write data row for i, value in ipairs(item) do file:write(value, " "); end
file:write("\n"); elseif type(item) == "number" then – check for pure numbers if plainArray == nil then plainArray = true elseif plainArray == false then write("Gnuplot Error: Data array mixes tables and numbers.\n"); return 1
end

file:write(i, " ", item, "\n"); else write("Gnuplot Error: Data array must contain only tables or only numbers.\n"); return 1
end end end

– close file file:close() end

example execution [[

plaindata = {5, 6, 7, 8} rowdata = {{3, 6, 4}, {4, 8, 5}, {5, 10, 6}, {6, 6, 7}} coldata = {{1,2,3,4}, {2,3,4,2}, {3,4,5,3}}

gnuplot.write_data("somedata.txt", data, false) gnuplot.plot("somedata.pdf", { {file="somedata.txt", 1, 2} –{file="somedata.txt", 1, 3} })

plots = { { label = "catsdogs", file = "./TestData/dogdata", style = "points", 1, 5 }, { label = "catsdogs3", file = "./TestData/dogdata", style = "points", 1, 6 }, { label = "catsdogs4", file = "./TestData/dogdata", style = "lines", 1, 5 }, { label = "catsdogs5", file = "./TestData/dogdata", style = "lines", 1, 6 }, { label = "catsdogs5", file = "./TestData/dogdata", style = "lines", 1, 6 }, { label = "sinuskurve",func = "sin(x)", style = "lines"}, { label = "rowdata_13", data = rowdata, row = true, style = "lines", 1, 3}, { label = "rowdata_12", data = rowdata, row = true, style = "lines"}, { label = "col data 12", data = coldata, style = "lines"}, { label = "col data 13", data = coldata, style = "lines", 1, 3} }

all options are optional options = { title = "Title", label = {x = "xAxis", y = "yAxis"} label = {"xAxis", "yAxis"} xlabel = "xAxis", ylabel = "yAxis", range = { x = {-100, 600}, y = {-5, 5} }, range = { {-100, 600}, {-5, 5} }, logscale = true, logscale = {x = true, y = false}, logscale = {true, false}, dim = 2, grid = true, key = true, timestamp = true, timestamp = "My Timestamp string", font = "Arial", fontsize = 10, multiplot = true, multiplotrows = 5, multiplotjoined = true, "additional param #1", "additional param #2", "additional param #3", ... }

gnuplot.plot("vibration.eps", plots, options) gnuplot.plot("vibration.svg", plots, options) gnuplot.plot("vibration.pdf", plots, options) gnuplot.plot("vibration.tex", plots, options) gnuplot.plot(nil, plots, options)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / gnuplot.lua :262-1296