plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.02k stars 2.54k forks source link

3D camera parameters with clear reference system and scale #1778

Closed ShapingView closed 3 months ago

ShapingView commented 5 years ago

Hello everyone,

I frequently have the issue with not being able to properly set the 3D camera parameters.

I don't see how the 3D camera setting parameters can be used to set the center or the eye on a specific location in the plotted 3D coordinate system.

Here comes a simple example:

# example as run in a Jupyter Notebook cell
import plotly.graph_objects as go
import numpy as np

fig = go.FigureWidget()

pointcloud1 = np.random.rand(3, 30) 
pointcloud2 = np.random.rand(3, 30) + np.array([10, 10, 10])[:, None]

fig.add_scatter3d(x=pointcloud1[0], y=pointcloud1[1], z=pointcloud1[2], name='cloud 1')
fig.add_scatter3d(x=pointcloud2[0], y=pointcloud2[1], z=pointcloud2[2], name='cloud 2')

fig.layout.scene.camera = go.layout.scene.Camera(
    center=dict(x=0, y=0, z=0),
    eye=dict(x=0, y=0, z=3),
    up=dict(x=0, y=1, z=0),
)

fig.layout.height = 500
fig.layout.width = 700
fig

The resulting plot looks like this:

image

The view is obviously centered somewhere in the middle between the point clouds, and the distance z=3 in the eye parameter does not correspond to the 3D graph distance as well (its more like 20 or 30).

Hope you guys can help me out here, since I did not find any way to work around this.

emmanuelle commented 5 years ago

Hi @ShapingView I think the coordinates given to camera attributes correspond to the scene domain, ie (0, 0, 0) is always the center of the domain. Don't know if it's possible to change this so that it refers to data coordinates instead...

ShapingView commented 5 years ago

Thanks for the response, @emmanuelle Is there a way to translate the camera attributes from the data domain into the scene domain parameters? If so, that would at least be a workaround.

emmanuelle commented 5 years ago

@ShapingView it is not possible at the moment, sorry. There is an open issue related to this, see https://github.com/plotly/plotly.js/issues/579

kmader commented 4 years ago

I also would be very interested in this feature or at least a way of figuring out the mapping between scene coordinates and data coordinates. Is there an affine or projection matrix somewhere?

gvwilson commented 3 months ago

Hi - we are currently trying to tidy up Plotly's public repositories to help us focus our efforts on things that will help users most. Since this issue has been sitting for several years, I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our backlog. Thanks for your help - @gvwilson