plotly_express
plotly_express copied to clipboard
Wrong Histogram chart with integer numbers
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:
expect result:

Thanks.
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'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