Skip to content

Low precision of scatter3d plot #5346

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

Closed
Koushikphy opened this issue Dec 16, 2020 · 3 comments
Closed

Low precision of scatter3d plot #5346

Koushikphy opened this issue Dec 16, 2020 · 3 comments

Comments

@Koushikphy
Copy link

I have this data that varies slowly in magnitude. If I plot this using Plotly's 2D scatter plot then it comes out okay, but get the following weired behaviour when I try to plot it using scatter3d. It seems scatter3d can't consider the slight change in value and plots it as a straight line with constant value.

Here's a sample script to generate the issue.

<!DOCTYPE html>
<body>
    <div id="graph1" style="height: 40vh;"></div>
    <div id="graph2" style="height: 60vh;"></div>
    <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
    <script>

        var data =[[0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02],[0,0.03490659,0.06981317,0.10471976,0.13962634,0.17453293,0.20943951,0.2443461,0.27925268,0.31415927,0.34906585,0.38397244,0.41887902,0.45378561,0.48869219,0.52359878,0.55850536,0.59341195,0.62831853,0.66322512,0.6981317,0.73303829,0.76794487,0.80285146,0.83775804,0.87266463,0.90757121,0.9424778,0.97738438,1.01229097,1.04719755,1.08210414,1.11701072,1.15191731,1.18682389,1.22173048,1.25663706,1.29154365,1.32645023,1.36135682,1.3962634,1.43116999,1.46607657,1.50098316,1.53588974,1.57079633,1.60570291,1.6406095,1.67551608,1.71042267,1.74532925,1.78023584,1.81514242,1.85004901,1.88495559,1.91986218,1.95476876,1.98967535,2.02458193,2.05948852,2.0943951,2.12930169,2.16420827,2.19911486,2.23402144,2.26892803,2.30383461,2.3387412,2.37364778,2.40855437,2.44346095,2.47836754,2.51327412,2.54818071,2.58308729,2.61799388,2.65290046,2.68780705,2.72271363,2.75762022,2.7925268,2.82743339,2.86233997,2.89724656,2.93215314,2.96705973,3.00196631,3.0368729,3.07177948,3.10668607,3.14159265],[-527.1404441,-527.140444,-527.1404439,-527.1404437,-527.1404435,-527.1404431,-527.1404427,-527.1404422,-527.1404417,-527.1404411,-527.1404404,-527.1404396,-527.1404388,-527.1404379,-527.1404369,-527.1404359,-527.1404348,-527.1404336,-527.1404324,-527.1404311,-527.1404298,-527.1404284,-527.140427,-527.1404254,-527.1404239,-527.1404223,-527.1404207,-527.140419,-527.1404172,-527.1404154,-527.1404136,-527.1404118,-527.1404099,-527.140408,-527.140406,-527.1404041,-527.1404021,-527.1404001,-527.140398,-527.140396,-527.1403939,-527.1403918,-527.1403897,-527.1403876,-527.1403856,-527.1403835,-527.1403856,-527.1403877,-527.1403898,-527.1403919,-527.140394,-527.140396,-527.1403981,-527.1404001,-527.1404021,-527.1404041,-527.1404061,-527.1404081,-527.14041,-527.1404119,-527.1404137,-527.1404155,-527.1404173,-527.140419,-527.1404207,-527.1404224,-527.140424,-527.1404255,-527.140427,-527.1404285,-527.1404298,-527.1404312,-527.1404325,-527.1404337,-527.1404348,-527.1404359,-527.140437,-527.1404379,-527.1404388,-527.1404397,-527.1404404,-527.1404411,-527.1404417,-527.1404423,-527.1404428,-527.1404432,-527.1404435,-527.1404438,-527.1404439,-527.1404441,-527.1404441]]
        const layout = {
            margin : { t:0,b:0,l:0,r:0}
        }
        Plotly.newPlot("graph1",
            [{
                "type" : "scatter",
                "mode" : "markers+lines",
                x : data[1],
                y : data[2],
            }], layout
        )

        Plotly.newPlot("graph2",
            [{
                "type" : "scatter3d",
                "mode" : "markers+lines",
                x : data[0],
                y : data[1],
                z : data[2],
            }],layout
        )

    </script>
</body>
</html>

Screenshot

@Koushikphy
Copy link
Author

any update on this?

@alexcjohnson
Copy link
Collaborator

Just came up again... the root issue here is that in WebGL numbers generally are single-precision floats, whereas elsewhere in JS they're double-precision. To fix this we would need to rescale all the input data prior to sending it to WebGL. Possible, but a fairly big project and may have performance implications.

@gvwilson
Copy link
Contributor

Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson

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