crosslang/octive-lean/PlotDemo.lean
Maximus Gorog 6592cd058d Add 'octive-lean/' from commit '4b6fcec565a170d7029d4ccba21be2ecd0512d13'
git-subtree-dir: octive-lean
git-subtree-mainline: fd3d42ae33
git-subtree-split: 4b6fcec565
2026-05-12 02:59:14 -06:00

106 lines
2.4 KiB
Text

import OctiveLean
-- Hover over each `octave!` block to see the rendered chart in the infoview.
-- Line plot of a sine wave
octave! {
x = linspace(0, 6.28, 64)
y = sin(x)
plot(x, y)
title("Sine Wave")
xlabel("x")
ylabel("sin(x)")
}
-- Scatter plot
octave! {
x = linspace(-3, 3, 40)
y = x .* x
scatter(x, y)
title("Parabola")
}
-- Bar chart
octave! {
bar([1, 2, 3, 4, 5], [3.2, 1.8, 4.5, 2.1, 3.9])
title("Bar Chart")
xlabel("Category")
ylabel("Value")
}
-- Histogram of residuals from a sine wave
octave! {
x = linspace(0, 6.28, 200)
y = sin(x) .* cos(x)
hist(y, 20)
title("Histogram of sin(x)*cos(x)")
xlabel("Value")
ylabel("Count")
}
-- Multi-series with hold_on / legend
octave! {
x = linspace(0, 6.28, 64)
hold_on()
plot(x, sin(x))
plot(x, cos(x))
hold_off()
legend("sin", "cos")
title("Trig Functions")
}
-- Stem plot
octave! {
x = linspace(0, 3.14, 16)
stem(x, sin(x))
title("Stem Plot")
}
-- ── 3-D: plot3 (helix) ───────────────────────────────────────────
octave! {
t = linspace(0, 12.57, 80)
xs = cos(t)
ys = sin(t)
zs = t .* 0.5
plot3(xs, ys, zs)
title("Helix")
xlabel("cos t")
ylabel("sin t")
zlabel("t/2")
}
-- ── 3-D: scatter3 ────────────────────────────────────────────────
octave! {
t = linspace(0, 6.28, 60)
scatter3(cos(t), sin(t), t)
title("Circular Scatter3")
}
-- ── 3-D: surf (corrugated wave) ──────────────────────────────────
octave! {
x = linspace(0, 6.28, 24)
y = linspace(0, 3, 12)
surf(x, y, sin(x))
title("Surface z = sin(x)")
xlabel("x")
ylabel("y")
zlabel("z")
}
-- ── 3-D: waterfall ───────────────────────────────────────────────
octave! {
x = linspace(0, 6.28, 30)
y = linspace(0, 3, 8)
waterfall(x, y, sin(x))
title("Waterfall")
}
-- ── 3-D: contourf ────────────────────────────────────────────────
octave! {
x = linspace(-3, 3, 30)
y = linspace(-3, 3, 30)
contourf(x, y, sin(x))
title("Contour: sin(x)")
xlabel("x")
ylabel("y")
}