Locking Turntable Rotation to Y-Axis in 3D Plots

Hello everyone,

Iā€™m working with 3D Scatter plots where itā€™s crucial to lock the turntable rotation to the Y-axis. The idea is to keep the Y-axis fixed while allowing rotation around it. While I understand that Plotlyā€™s default behavior is to rotate around the Z-axis, this doesnā€™t meet my specific needs.

Iā€™m aware of a trick where you can swap the Y and Z axes while adding traces, thereby giving the impression of Y-axis rotation. However, this approach isnā€™t suitable for my use case. My application deals with points that have meaningful X, Y, Z coordinates, and itā€™s important for the users to know these values as they are.

Does anyone know a workaround for this issue? Or could this feature possibly be added in a future release?

Thank you for your time and help.

HI @jmahmud,

Are you referring to rotation around y-axis? Imagine if you first enable orbital rotation, the user rotates the figure, enables turntable rotation?

Is the expectation that the Scatter3D rotates around the changed y-axis?

Are you open to use dash? There might be ways to emulate something like this.

Hi @AIMPED, thank you for your reply!

Indeed, I am referring to rotation around the Y-axis when using the turntable rotation. I am working on visualizing some cuboids, 3D lines, and point clouds, where the Y-axis is designated as ā€˜up.ā€™ Due to this orientation, turntable rotation around the default Z-axis is unintuitive for users who expect ā€˜upā€™ to remain constant.

Unfortunately, using Dash apps is not an option for me; I need to create standalone HTML files for these visualizations.

Any insights or workarounds would be greatly appreciated!

Could you provide some sample data and code explaining why this does not work for you? I canā€™t check right now, but it should be possible to tweak axis labels and hoverinfo to give the user the ā€œcorrectā€ impression.

1 Like

Awesome hint and this solves my problem! I did not realize we can easily update hovertemplate for almost any 3D entity.

In case someone stumbles upon this, what I needed to do to enable this:

  1. Swap Y and Z values whenever I use Scatter3D/Cone/Mesh3D
  2. For each of the above, set up a hover template like "x=%{x:.3f}, y=%{z:.3f}, z=%{y:.3f}<br>"
  3. Update the layout up direction and rename Y and Z axis:
    fig.update_layout( scene_camera={"up": {"x": 0.0, "y": 1.0, "z": 0.0}}, scene={ "dragmode": "turntable", "yaxis": {"title": "Z"}, "zaxis": {"title": "Y"}, }, )

With all these changes the code works exactly as intended.

1 Like