plotly wrongly automatically converts strings to integers if possible
toolslive opened this issue · 2 comments
toolslive commented
<head>
<script src='https://cdn.plot.ly/plotly-2.35.0.min.js'></script>
</head>
<body>
<div id='myDiv'>
</div>
<script>
//var x = [1,2,3,4] // interpreted as number
//var x = ['a','b','c', 'd']; // used as labels
var x = ['-1','1e1', '0x64']; // now they're numbers :(
var trace1 = {
x: x,
y: [10, 15, 13, 17],
type: 'scatter'
};
var trace2 = {
x: x,
y: [16, 5, 11, 9],
type: 'scatter'
};
var data = [trace1, trace2];
Plotly.newPlot('myDiv', data);
</script>
</body>
It should just use strings as labels (just like what happens when x= ['a','b','c','d']
).
A simple work around is to prefix the strings with
to sabotage the convertion.
my-tien commented
You can set layout.xaxis.type = 'category'
to keep the strings.
alexcjohnson commented
You can also set layout.autotypenumbers = 'strict'
(which is currently in the default plotly.py template, but in plain plotly.js the default is 'convert types'
) https://plotly.com/javascript/reference/layout/#layout-autotypenumbers