Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plotly wrongly automatically converts strings to integers if possible #7147

Open
toolslive opened this issue Sep 10, 2024 · 2 comments
Open

Comments

@toolslive
Copy link

<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>

plotly_ducktyping

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 &nbsp; to sabotage the convertion.

@toolslive toolslive changed the title plotly, wrongly automatically converts strings to integers if possible plotly wrongly automatically converts strings to integers if possible Sep 10, 2024
@my-tien
Copy link
Contributor

my-tien commented Sep 10, 2024

You can set layout.xaxis.type = 'category' to keep the strings.

@alexcjohnson
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants