我正在生成非常基本的 plotly.js
直方图,例如来自 plotly
tutorial 的示例。 :
var x = [];
for (var i = 0; i < 500; i ++) {
x[i] = Math.random();
}
var data = [
{
x: x,
type: 'histogram',
marker: {
color: 'rgba(100,250,100,0.7)',
},
}
];
Plotly.newPlot('myDiv', data);
是否可以以某种方式指定容器大小/窗口?
最佳答案
您可以使用nbinsx
调整垃圾箱的数量。参数。
var x = [];
for (var i = 0; i < 5000; i ++) {
x[i] = Math.random();
}
var data = [
{
x: x,
type: 'histogram',
}
];
Plotly.newPlot('default', data, {title: "default bin"});
data = [
{
x: x,
type: 'histogram',
nbinsx: 10
}
];
Plotly.newPlot('bins_10', data, {title: "10 bins"});
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<div id="default" style="width: 480px; height: 400px;"></div>
<div id="bins_10" style="width: 480px; height: 400px;"></div>
关于javascript - 在直方图中指定 bin 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41753200/