# Camera eye parameters

Hi Experts,

I struggled to find the parameters that allowe me to view from above, with X-axis sitting horizontal and increase value from left to right, Y-axis sitting vertial and increase vaule from down to up, which is more common than the current [View from Above (X-Y plane)] in your intro page.

Thanks!

@alexalex You cannot get the plot of a 3d object in your preferred system of coordinates (i.e. OpenGL system of coords) just by changing the viewer position. You have to transform your data x, y,z, expressed in the world (Plotly) coordinate system, to coordinates in your system, and change the axes labels (titles).
First I represent a cone of equation z=1.5\sqrt{x^2+y^2} in the Plotly system of coords. Then I define the linear transformation, represented by a matrix, from the plotly syst to your syst, and apply this transformation to the dstacked data [x,y,z], such that in the new system the cone vertex is at origin and zaxis is its symmetry axis, exactly as in the case of Plotly coordinate system.

import plotly.graph_objects as go
import numpy as np
from numpy import pi, sin, cos
u = np.linspace(0,0.75, 20)
v = np.linspace(0, 2*pi, 100)
u, v = np.meshgrid(u,v)
x = u*cos(v)
y = u*sin(v)
z = 1.5*u

fig = go.Figure(go.Surface(x=x, y=y, z=z))
fig.update_layout(scene_camera_eye=dict(x=1.5, y=1.5, z=1), font_size=10)


Transformations:

def transf():
return np.array([[0, 1, 0], [0, 0, 1], [1, 0, 0]])
def transf_data(x, y, z):
X, Y, Z = np.einsum('ji, mni -> jmn', transf().T, np.dstack([x, y, z]))
return X, Y, Z

X, Y, Z = transf_data(x,y,z)
fig.update_traces(x=X, y=Y, z=Z)
fig.update_scenes(xaxis_title="z", yaxis_title="x", zaxis_title="y")


Depending on your data, you can now change the position of the viewer to get the 3d object displayed such that to reveal some property.

1 Like

If you want to play around with the parameters, I created a dash app a while ago:

2 Likes

@AIMPED I havenβt dash installed on my machine. I added a suplementary explanation on how the plot in the opengl system of coordinates should look like. Please let us know how do you change the camera_eye parameters to get such a plot.

Thank you for saving me from the endless conversation with ChatGPT4.0

For future users interested in using such a coordinate system. The solution is setting camera_up=dict(x=0, y=1, z=0).
Its presence in layout settings triggers plotly.js (behind the scenes) to do the calculations that I did above in python:

import plotly.graph_objects as go
import numpy as np
from numpy import pi, sin, cos

u= np.linspace(0,0.75, 20)
v=np.linspace(0, 2*pi, 100)
u, v=np.meshgrid(u,v)
x=u*cos(v)
y=u*sin(v)
z=1.5*u
fig=go.Figure(go.Surface(x=x, y=y, z=z))
fig.update_layout(scene_camera=dict(eye=dict(x=1.5, y=1.5, z=1) ,
up=dict(x=0, y=1, z=0)), font_size=10)


3 Likes