javascript - 在直方图中指定 bin 大小

标签 javascript plotly

我正在生成非常基本的 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/

相关文章:

javascript - 当在同一页面上使用多个绘图时,Plotly.js 只有一个绘图可以工作

r - 在 Rmarkdown(knitr chunk)文档中生成的多个(R)绘图图形

python - 如何使用 Dash plotly 添加/创建自定义加载程序?

scala - 在 Scala 中与齐柏林飞艇一起使用 plotly

javascript - 为什么这个 jQuery 会对这个 div 类的两个实例进行动画处理?

javascript - 使用javascript创建一个没有table标签的带有div的二维表格

python - 阴谋地徘徊

JavaScript 执行函数时出错 : 2 arguments required but only 1 present

javascript - 从给定的 HTML 文本获取 JQuery?

javascript - 未捕获的语法错误 : Unexpected token { function js