javascript - 如何删除plotly.js 图表轴中的非整数?

标签 javascript plotly

return {
  height: 210,
  title: title,
  autosize: true,
  width: '100%',
  font: {
    size: 10,
    family: "Roboto"
  },
  showlegend: false,
  margin: {
    l: 40,
    r: 10,
    b: 35,
    t: 22,
    pad: 0
  },
  xaxis: {
    nticks: 6,
    title: "Score",
    linecolor: '#cccccc',
    zerolinewidth: 0,
    zerolinecolor: '#fff'
  },
  yaxis: {
    title: "Number of students",
    linecolor: '#cccccc',
    zerolinewidth: 0,
    zerolinecolor: '#eeeeee',
    range: [0, numStudents]
  },
  bargap: 0.5
};

这包括半音以及1.5等等。我正在使用plotly.js,这就是我所看到的:

enter image description here

最佳答案

您可以通过设置 dtick 强制 Plotly 使用轴刻度之间的定义距离。在你的轴的 layout 选项中,即在你的情况下它是

{yaxis: {dtick: 1}}

请参阅下面的无 layout 设置与固定 dtick 设置的示例。

var trace1 = {
  x: ['A', 'B', 'C'],
  y: [1, 3, 2],
  mode: 'markers',
  type: 'bar'
};

Plotly.newPlot('myPlot1', [trace1], {yaxis: {dtick: 1}});
Plotly.newPlot('myPlot2', [trace1]);
<script src="https://cdn.plot.ly/plotly-latest.min.js">
</script>
<div id = "myPlot1" ></div>
<div id = "myPlot2" ></div>

关于javascript - 如何删除plotly.js 图表轴中的非整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46245740/

相关文章:

javascript - Angular 未知提供者,其工厂封装在匿名函数中

python - 用于绘图 slider 小部件的悬停工具(python)

javascript - 如何减少 plotly js 中标题和圆环图之间的空间?

r - 在 R 中的 Shiny 应用程序中动态绘制 Plotly 图形

r - 在绘图中的点 0 处添加 3d 曲面

javascript - Firefox 插件 SDK 替换请求

javascript - Angular JS : Increment a Counter in a Service From Controller

javascript - CSS 转换立即进入最终状态

javascript - 将今天日期转换为其他格式

python - 您将如何在 Python 中绘制此 3D 可视化图?