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

Dash graph cannot display correct labels with pure numbers

I am currently working on a few web apps based on DASH. I found out no matter which graph (scatter, bar and heatmap etc.) I used, the x and y labels could not display correctly with pure numbers. initially I thought it’s a regular issue with data type format, then I converted it to str format and it still had the same issue. So I have to put a little dash ‘-’ sign next to the ‘pure numbers’ in order to make it display correctly as you can see in the picture above. Any suggestions?

Plotly automatically checks if the data is numerical, categorical (strings), or dates. If you would like to treat your numerical data as categorical data (e.g. strings), then you can explicitly set the type of the xaxis to 'category' (https://plot.ly/python/reference/#layout-xaxis-type), e.g.

figure = {
    'data': [{'x': [1, 5, 9], 'y': [2, 1, 3]}],
    'layout': {'xaxis': {'type': 'category'}}
}
1 Like