crosslang/PlotDemo.lean
Maximus Gorog 4b6fcec565 Add SymPy bridge and migrate DSL to brace-block syntax.
Symbolic computation via a persistent Python subprocess: new `.sym`
Value variant carries (srepr, pretty), `OctiveLean.SymPyBridge` owns
the subprocess and round-trips expressions, and `evalBinOp`/unary
negation route through SymPy when either operand is `.sym`.  Corpus
adds sym_basic, sym_solve_simplify, sym_calc; demos add Lorenz,
Van der Pol, gravity, SymToolboxDemo, Lab7Interp.

DSL surface changes from `octave! ... octave_end` to `octave! { ... }`.
RosettaStone rewritten against the new syntax; PlotDemo updated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 02:58:50 -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")
}