简体   繁体   中英

Change the step of a histogram in plotly.js


I'm using plotly.js to try to represent a statistical dataset. ie draw a histgram for sizes. My trace is the following

const trace = {
 type: 'histogram',
 x: [1.8, 1.6, 1.6, 1.65, 1.9, 1.62, 1.76, 1.74, 1.82, 1.7]
}

Then I use it with Plotly.newPlot('myDiv', [trace]); But the histogram I get has steps of 0.1, meaning that I get only 3 columns for 1.6-1.69, 1.7-1.79 and 1.8-1.89. The question is simple, how to change it to have a step of, for example, 0.05 ?

You can use xbins property for example

const trace = {
 type: 'histogram',
 xbins: {size: 0.05, start: 0, end: 2},
 x: [1.8, 1.6, 1.6, 1.65, 1.9, 1.62, 1.76, 1.74, 1.82, 1.7]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM