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

Bug in how Bar plot handles int-like strings?

I’m not sure if it’s appropriate to submit bug reports here (or what I think is in one). Hopefully if not, someone can point me in the right direction. Or tell me what I’m doing wrong, if this is not a bug.

Summary: If I create a bar plot with a string or categorical variable as the bar labels, and if the string looks like something that can be coerced to an int, then Plotly will treat it as an int. This is often not appropriate, and reduces flexibility.

To illustrate, the following bar plot works fine:

go.Bar(x=['Brunswick', 'Preston', 'Northcote'], y=[33,55,42])

This gives three evenly-spaced bars, as I’d expect.

However if instead of suburb names I try to use postcodes:

go.Bar(x=['3056', '3072', '3070'], y=[33,55,42])

then the postcodes seem to be coerced into integers and so there is a large gap on the x-axis between 3056 and 3070, and the bars are reordered into numerical order. If I’d passed in [3056, 3072, 3070], this would be what I’d want to happen. But if I pass in strings, or if I am using a Pandas DataFrame with categorical variables that get transformed into strings in the JSON, then I want my variable to be treated as a category.

Note that if I put some kind of character in the string so it doesn’t look like an int any more, everything is fine. For instance

go.Bar(x=['Z3056', 'Z3072', 'Z3070'], y=[33,55,42])

works, although I of course I don’t actually want Z in my labels.

Is this a bug? Is there some way for me to force Plotly to treat my strings as category labels and not as ints?