Black Lives Matter. Please consider donating to Black Girls Code today.

Same parameter applied to 'data'[...] doesn't match with the value in 'layout'[...]

I am trying to use ‘categoryorder’ and ‘categoryarray’ in the layout to sort the sequence. The sequence can be sorted without any problems and shown perfectly fine on the bar chart. However, when I pass a series (same keys as categoryarray’ to the trace data, the sequence seems not matching with the ‘layout’. Is there a way to match them?

Here is the code:

'data': [
            go.Bar(
                x=df4_rate,
                y=df4_rate.index,
                error_x=dict(
                        type='data',
                        symmetric=False,
                        array=df4_confint[1].subtract(df4_rate),
                        arrayminus=df4_rate.subtract(df4_confint[0]),
                        visible=True
                    ),
                orientation='h',
                name=org_name,
                text=pval_array,
                hoverinfo = 'text',
                marker=dict(
                    color='#711471'
                ) 
            )
        ],
        'layout': go.Layout(
            xaxis={
                'range': [0, 1]
            },
            yaxis={
                'showticklabels': True,
                'categoryorder': "array",
                'categoryarray': pval_array.keys(),
            },
            margin={'l': 300, 'b': 50, 't': 50, 'r': 0},
            height=600,
            hovermode='closest',
            barmode='group',
        )

Could you extract the the data values into a small, simple, reproducable example? For example:


categoryarray = ['a', 'b', 'c']
x = [1, 2, 3]
y = [4, 1, 2]

app.layout = dcc.Graph(id='graph', figure={
    'data': [go.Bar(x=x, y=y), 'layout': {
    'yaxis': {'categoryorder': 'array', 'categoryarray': categoryarray}
})

That’ll make it a lot easier for us to help you / understand if this is a bug or not

The problem has been solved. Thanks!