diff --git a/plot.ts b/plot.ts index dd4430c..79e5e36 100644 --- a/plot.ts +++ b/plot.ts @@ -6,4 +6,10 @@ export const document = new DOMParser().parseFromString( export const plot = (data) => { return Plot.line(data, {x: "x", y: "y"}).plot({y: {grid: true}, document}) +} + +export const plotxy = (xmin, xmax, step, y) => { + const x = Array.from({length: (xmax - xmin)/step}, (_, i) => (i - xmin) * step) + const data = x.map(x => ({x, y: y(x)})) + return Plot.line(data, {x: "x", y: "y"}).plot({y: {grid: true}, document}) } \ No newline at end of file