Plotly.js 绘制 y = 3x^2 曲线 - 示例代码和教程
以下是使用 Plotly.js 绘制 y = 3x^2 的曲线的示例代码:
<!DOCTYPE html>
<html>
<head>
<script src='https://cdn.plot.ly/plotly-latest.min.js'></script>
</head>
<body>
<div id='plot'></div>
<script>
var x = [];
var y = [];
for(var i = -10; i <= 10; i += 0.1) {
x.push(i);
y.push(3 * Math.pow(i, 2));
}
var trace = {
x: x,
y: y,
type: 'scatter',
mode: 'lines',
line: {
color: 'blue',
width: 2
}
};
var layout = {
title: 'y = 3x^2',
xaxis: {
title: 'x'
},
yaxis: {
title: 'y'
}
};
Plotly.newPlot('plot', [trace], layout);
</script>
</body>
</html>
该代码会生成一个包含 y = 3x^2 曲线的图表,并在页面中显示。可以根据需要调整 x 轴和 y 轴的范围、曲线颜色、宽度、标题等属性。
原文地址: https://www.cveoy.top/t/topic/mE2P 著作权归作者所有。请勿转载和采集!