How to plot categorical values in x

Hi,

A newbie here. I am trying to plot data as categorical in plotly but it’s being treated as a linear sequence and I end up with a lot of space in between data values that I do not need. How do I go about correcting this?

Thanks.

Hi @jumaxbrian, welcome to the forum!

You can force the xaxis to be categorical as described here

import plotly.express as px
fig = px.bar(x=[1, 10, 100], y=[2, 1, 4,])
fig.update_layout(xaxis_type='category')
fig.show()

Hi Emmanuelle,

Thanks.

However, it doesn’t work for me in plotly.graph_objs when I put it under layout i.e.

'layout': {
                'title': 'Dash Data Visualization',
                'xaxis_type': 'category',
                'barmode': 'stack'
            }

Oh yes, I used here our magic underscore. Just do 'xaxis':{'type':'category'}.

1 Like

Perfect, thanks. This is what I needed.