🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Plotly reading numbers instead of text

My values are:

x = [32, 13, 24, 7, 9]
y = [‘0’, ‘1’, ‘2 to 5’, ‘6 to 10’, ‘>10’]

It looks like plotly things that my y values are numbers and plots the 2 first values of my list (0 and 1).

My chart then shows as y ticks: -0.5, 0, 0.5, 1, 1.5 instead of ‘0’, ‘1’, ‘2 to 5’, ‘6 to 10’, ‘>10’.

How do I do to tell plotly that my y values are strings and not numbers ?

Thanks for your help.

@christianv You can do this by using the layout.yaxis.type attribute. Setting it to 'categorical' should do the trick.

Thank you very much Michael for your help. How should I write this into the following code ?

data = [go.Bar(x=x, y=y, text=x, textposition = ‘auto’, orientation=‘h’, marker=dict(color=colors))]
layout = go.Layout(margin=go.layout.Margin(l=530, r=50, b=90, t=90, pad=25), autosize=False, width=2000, height=1000, font=dict(size=45))
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename=‘horizontal-bar’)
pio.write_image(fig, Q2.jpg")

In advance, thank you for your help.

found it:

layout = go.Layout(margin=go.layout.Margin(l=200, r=50, b=90, t=90, pad=25), autosize=False, width=2000, height=800, font=dict(size=45), yaxis=dict(type=“category”))