plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
16.92k stars 1.85k forks source link

aspectmode=data is incorrect when cones and scatter points are both involved #7143

Open alexcjohnson opened 2 weeks ago

alexcjohnson commented 2 weeks ago

See https://codepen.io/alexcjohnson/pen/ExBryzb?editors=0010

When all traces in this plot are shown, the square is not square:

Screenshot 2024-09-08 at 17 58 11

But if you click the legend to hide the cone trace, you do get a square:

Screenshot 2024-09-08 at 17 58 36

This is a pretty important bug for anyone making a plot representing real 3D space, as shapes will be distorted and the only workaround I could find is to abandon axis autorange: set explicit ranges for all three axes, set aspectmode: 'manual', and calculate aspectratio.{x, y, z} explicitly.

I haven't been able to reproduce this issue with only scatter3d traces, nor have I tried with other trace types or with just cones, but my guess is we're calculating the axis aspect ratios before adding extra padding to the ranges to accommodate the cones. Ironically it appears we don't pad the axes (not at all? not very much? I can't quite tell) for scatter3d points, but that's a separate issue.

As a side note: it would be nice if aspectratio or aspectmode docs stated that aspectratio is ignored when you set aspectmode: 'data'. I've seen users try to use this combination of attributes to create vertical exaggeration of topography, but this fails (and again, the only solution I can find is to calculate everything manually).