Search code examples
pandasplotly

Plotly histogram starts with negative value, even though none in data


enter image description here

Hi all! When plotting the distribution of data with Plotly, I've noticed that the histogram bins start at a negative value (here -0.25) even though my dataset has no negative value (see below the mins, avg_time_per_user here starts at 0).

I've tried playing around with the number of bins which makes no difference. The only thing that makes the histogram correctly start at 0 is removing nbins=n entirely, which is not ideal as I want to be able to control it.

Thanks in advance!


Solution

  • I have found a solution while Googling some more: using a dict to define the bins. This worked like a charm in having the correct first bin delimitation.

    fig.update_traces(xbins=dict( 
            start=0.0,
            end=5.0,
            size=0.5))
    

    enter image description here