Programming Environment for Numerical Computing
 Guide Math Algebra ODE Parser Data Plot Time Socket

XY Plotting

The plot namespace includes functions to plot data:

Example #1:

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
-- set curve #1 line size
plot.set(p, 1, "size", 2)
-- set curve #1 style(line and marker)
plot.set(p, 1, "style", "-o")
plot.set(p, 1, "color", "0000FF")
plot.update(p)

Example #2:

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

-- Real-time plot

x = {}
y = {}
x = 1
-- random number between 0 and 1
y = math.random()

--create a plot
p = plot.new()
--add curve to the new plot
--set curve #1 line size
plot.set(p, 1, "size", 2)
--set curve #1 style (line and marker)
plot.set(p, 1, "style", "-o")
--set the maximum number of points
plot.set(p, "maxpoints", 21)
plot.update(p)

-- the total number of points (only the last 21 points will be displayed)
n = 100
-- update the curve every 200 milliseconds
for i = 2, n, 1 do
x = i
-- random number between 0 and 1
y = math.random()
-- add new data to curve #1