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

Sha*_*oon 3 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
};
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述

Max*_*ers 6

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

{yaxis: {dtick: 1}}
Run Code Online (Sandbox Code Playgroud)

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

{yaxis: {dtick: 1}}
Run Code Online (Sandbox Code Playgroud)
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]);
Run Code Online (Sandbox Code Playgroud)