I'm drawing plotly 3D graph and want to adjust camera position. The best way to do it for me is to use viewer, zoom and rotate scene as needed, then grab camera position as JSON and put it into my script that generate the picture to achieve the same position by default.
According to this tweet, it should be working, but it doesn't.
My code is:
from plotly.graph_objs import Scatter3d, Layout, Scene
from plotly.offline import iplot
import plotly
from numpy import sin, cos, linspace, pi, zeros_like
plotly.offline.init_notebook_mode()
t = linspace(0, 4*pi)
trace1 = Scatter3d(
x = t,
y = cos(t),
z = sin(t),
mode = 'lines'
)
layout = Layout(
width = 600,
height = 600,
scene = Scene(
xaxis = {'title': 't'},
yaxis = {'title': 'x'},
zaxis = {'title': 'y'},
camera =
{'eye':{'x':0,'y':1,'z':0},
'up': {'x':0,'y':0,'z':1},
'center': {'x':0,'y':0,'z':0}}
)
)
iplot(dict(data=[trace1], layout=layout))
Then I get a picture:
click 'save and edit in the cloud', switch to plotly interface, adjust camera position and click View JSON and still get the default camera position as I specified in Layout.
This is the intended behavior.
plotly.js doesn't save the camera position before sending it to the plot.ly cloud. You'll need to save your graph in the plotly workspace at plot.ly/plot in order to update its
camera
attribute.Here's a full explanation with examples of Plotly's camera controls for 3d plots:
http://nbviewer.jupyter.org/github/etpinard/plotly-misc-nbs/blob/master/3d-camera-controls.ipynb
For the sake of completeness, here is a short summary:
It is possible to use
camera
instead ofcameraposition
as it seems to have simpler explanation.The camera position is determined by three vectors:
up
,center
,eye
.The up vector determines the up direction on the page. The default is
(x=0, y=0, z=1)
, that is, the z-axis points up.The center vector determines the translation about the center of the scene. By default, there is no translation: the center vector is
(x=0, y=0, z=0)
.The eye vector determines the camera view point about the origin. The default is
(x=1.25, y=1.25, z=1.25)
.It is also possible to zooming in by reducing the norm the eye vector.