如何在plot.ly中将y轴格式化为百分比?在var布局中,我对y轴有以下设置:
yaxis: { hoverformat: ",.0%" },
这会将悬停更改为百分比,但y轴上打印的值仍然是0-1而不是0-100.
任何帮助深表感谢.
解决方法
要更改y轴的格式,需要设置
tickformat
,而不是hoverformat.
var trace1 = { x: [1,2,3,4],y: [0.10,0.15,0.43,0.17],type: 'scatter' }; var trace2 = { x: [1,y: [0.16,0.5,0.11,0.9],type: 'scatter' }; var layout = { yaxis: { tickformat: ',.0%',range: [0,1] } } var data = [trace1,trace2]; Plotly.newPlot('myDiv',data,layout);
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script> <div id="myDiv" style="width: 480px; height: 400px;">