使用plotlyjs绘制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/bedu 著作权归作者所有。请勿转载和采集!