Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Ticks on Histogram

Hi!

I am trying to build two histograms out of a list of integer (also tried converting each integer to string as ‘categorizing’ but it didn’t work).

So I have a bunch of numbers between 1 and 4 and I want the Percentage-Histogram of those. However, I can’t get the ticks to be [0,1,2,3,4] and be centered at each bin.

Here the code:

def histogram(goals, t, title):

    '''
    data = pd.DataFrame with 2 columns (scored and recieved)
               each one has 38 integers between 0-4
    '''
    
    names = ['Anotados', 'Encajados']
    colors = ['rgba(55, 128, 191, 0.7)', 'rgba(219, 64, 82, 0.7)']
    
    traces = []
    for c in range(2):
        x = data.values[:,c]
        traces.append(go.Histogram(
            x=x,
            histnorm='percent',
            name=names[c],
            xbins=dict(
                start=min(x),
                end=max(x),
                size=1
            ),
            marker=dict(
                color=colors[c],
            )))
            
    layout = go.Layout(
        title=title,
        height=300,
        xaxis=dict(
            title='Goles'
        ),
        yaxis=dict(
            title='%'
        ),
        bargap=0.2,
        bargroupgap=0.1
    )
            
    return {'data':traces, 'layout':layout}

This is the result:

How is it possible that they have different axes if they share the same definition and the data is all integers?

** How can I make the 0, 1, … to be at the center of each group of bins?

Thanks!