运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <script src="myplotlib.js"></script> <body> <canvas id="myCanvas" width="400px" height="400px" style="width:100%;max-width:400px;border:1px solid black"></canvas> <script> // Create a Plotter const plotter = new XYPlotter("myCanvas"); plotter.transformXY(); const xMax = plotter.xMax; const yMax = plotter.yMax; const xMin = plotter.xMin; const yMin = plotter.yMin; // Create Random XY Points const numPoints = 500; const xPoints = []; const yPoints = []; for (let i = 0; i < numPoints; i++) { xPoints[i] = Math.random() * xMax; yPoints[i] = Math.random() * yMax; } // Line Function function f(x) { return x * 1.2 + 50; } //Plot the Points and the Line plotter.plotPoints(numPoints, xPoints, yPoints, "blue"); plotter.plotLine(xMin, f(xMin), xMax, f(xMax), "black"); </script> </body> </html>