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

时间:2017-09-15 18:42:52

标签: 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}}等等。我正在使用plotly.js,这就是我所看到的:

enter image description here

1 个答案:

答案 0 :(得分:1)

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

{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>
&#13;
&#13;
&#13;