plotly_express icon indicating copy to clipboard operation
plotly_express copied to clipboard

Wrong Histogram chart with integer numbers

Open dmib opened this issue 6 years ago • 2 comments

Step to reproduce:

import plotly.express as px
tips = px.data.tips()
tips = tips[tips["size"].isin([1,4,6])]
fig = px.histogram(tips, x="size", y="tip", histfunc='count')
fig.show()

output:

image expect result:

image

Thanks.

dmib avatar Aug 19 '19 13:08 dmib

By default it used 4 bins and merge data from neighboring columns into one. Specify number of bins: fig = px.histogram(tips, x="size", y="tip", histfunc='count', nbins=len(tips))

nazariyb avatar Nov 27 '19 13:11 nazariyb

@nazariyb's answer is pretty much what I would write. The bins in your first figure are correct, they just span multiple sizes, and you can control this behaviour with nbins

nicolaskruchten avatar Nov 27 '19 15:11 nicolaskruchten