plotting
Data plotting module. Currently, this module supports line and scatter plotting.
There are no constants.
line_plotter
construct()
add_data()
get_dotcolour()
get_dotwidth()
get_linecolour()
get_linestyle()
plotter
construct()
auto_expand()
get_axiscolour()
get_backcolour()
' Example 1: Plot random data
import gui, math
import plotting
start
window = gui_window("Plotting", 500, 400)
p = line_plotter(window, 14, 14, 470, 350)
p.set_title("Data Plot")
p.set_xlabel("Time (s)")
p.set_ylabel("Voltage (V)")
p.set_bounds(0, 100, 0, 10)
data = get_data()
p.set_data(data)
p.plot()
window.show()
stop
function get_data()
data = []
for i, 0, 100
append(data, [i, random(2, 4)])
endfor
return data
stop
' Example 2: Plot sine function
import gui, math
import plotting
start
window = gui_window("Plotting", 500, 400)
p = line_plotter(window, 14, 14, 470, 350)
p.set_title("Sine Graph")
p.set_xlabel("x")
p.set_ylabel("y")
p.set_bounds(0, 720, -1, 1)
data = get_fx(sind(), 0, 720, 1)
p.set_data(data)
p.plot()
window.show()
stop
' Example 3: Plot heart sign
import gui, math
import plotting
start
window = gui_window("Plotting", 460, 400)
p = line_plotter(window, 14, 14, 420, 350)
p.set_title("Love is on the Code")
p.set_xlabel("x")
p.set_ylabel("y")
p.set_bounds(-20, 20, 0, 10)
p.set_linecolour(colour.hex("fe7294"))
p.set_data(get_fxy(love(), -10, 10, 0.1))
p.plot()
window.show()
stop
function love(t)
return [
16 * sin(t) ^ 3,
13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)
]
stop
' Example 4: Scatter plot
import gui, math
import plotting
start
window = gui_window("Plotting", 460, 400)
p = line_plotter(window, 14, 14, 420, 350)
p.set_title("Scatter Plot")
p.set_xlabel("x")
p.set_ylabel("y")
p.set_bounds(0, 100, 0, 100)
p.show_dots(true)
p.hide_lines(true)
p.set_data(get_fxy(sample(), 0, 100, 1))
p.plot()
window.show()
stop
function sample()
return [random(10, 90), random(10, 90)]
stop