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

How to plot categorical values in x


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?


Hi @jumaxbrian, welcome to the forum!

You can force the xaxis to be categorical as described here

import as px
fig =[1, 10, 100], y=[2, 1, 4,])

Hi Emmanuelle,


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.