For Science and Engineering hamady.org
Programming Environment for Numerical Computing

XY Plotting

The plot namespace includes functions to plot data:

 p = plot.new(width, height, template) Create plot. Returns the plot identifier,     or nil if error plot.add(p, x, y) add a curve with tables x,y plot.add(p, x, y, ey) adds a curve with tables x,y and error bar table ey plot.add(p, x, y, ex, ey) adds a curve with tables x,y and error bar tables ex,ey plot.add(p, curve, x, y) add tables x,y to an existing curve plot.add(p, curve, x, y, ey) adds tables x,y to an existing curve, with error bar table ey plot.add(p, curve, x, y, ex, ey) adds tables x,y to an existing curve, with error bar tables ex,ey plot.add(p, expr, npoints, xstart, xend) add a curve with: expression (like "sin(x)", "1 - exp(-x)" …) number of points npoints interval from xstart to xend plot.add(p, fname) add a curve from data file (columns 1 and 2, TAB separated) plot.set(p, curve, prop, val) set the curve properties. prop can be: "size" for curve line and symbol size.     val is the size ("1", "2" ...) "style" for curve style.     val is "o" for circle, "+" for plus sign,     "s" for square, "d" for diamond,     and "-" for line.     Example: "-s" for line and squared markers. "legend" for curve legend.     val is the legend text. "color" for curve color.     val is color name like "red", "blue", ...     or hex-value like "FF0000") plot.set(p, prop, val) set the plot properties. prop can be: "title" for the plot window title.  val is the window title. "xlabel" for the bottom axis label.  val is the axis label. "ylabel" for the left axis label.  val is the axis label. "xscale" for the bottom axis scale:  val is "log" or "linear". "yscale" for the left axis scale:  val is "log" or "linear". "xlim" for the bottom axis scale:  val is "[min,max]" where min and max are the x-axis limits. "ylim" for the left axis scale:  val is "[min,max]" where min and max are the y-axis limits. "maxpoints" set val as the maximum number of points per curve. "autolim". val is "true": automatically set the axis limits. plot.save(p, fname) save plot to file (SVG vectorial or PNG raster image) plot.update(p) update the plot window plot.close(p) close the plot window

Example:

Copy the following script in the editor and click Run (or press F12 on Windows and Linux)

-- Plot
x = {0,1,2,3,4,5}
y = {0,1,2,3,4,5}
-- create a plot
p = plot.new(800, 600)
plot.set(p, "title", "Plot example")
-- add curve to the new plot