LeanPlot: Interactive Plotting for Lean 4

2.2. Your First Plot🔗

Create a new .lean file, import LeanPlot, and use the #plot command:

import LeanPlot.API
import LeanPlot.DSL
#plot (fun x => x^2)

Simple quadratic plot

This renders a parabola with automatic axis labels and styling in the VS Code infoview!

2.2.1. Customizing Samples

You can customize the number of sample points:

#plot (fun t => Float.sin t) using 400

2.2.2. Multiple Functions

For multiple functions on the same chart, use plotMany:

#html plotMany #[("sin", fun x => Float.sin x), ("cos", fun x => Float.cos x)]

Sin and cos comparison

This automatically assigns colors and creates a legend.

2.2.3. More Examples

Damped oscillation:

Damped oscillation

Tanh activation function:

#plot Float.tanh

Tanh function

Scatter plot:

#html scatter (fun x => x^2 + 0.1 * Float.sin (10 * x)) (steps := 50)

Scatter plot