How to get/change current scene/camera in 3D plot - inside Jupyter notebook (Python)

Say I have run plotted this 3D surface in a Jupyter notebook in Python:

Now I move it around a bit and then I would like to grab the camera position and other scene parameters.
So I can plot with this viewpoint.

But also I would like to grab them to be able to programmatically rotate/animate the 3D plot, ideally using IPython widgets ( For that I need a handler to the js object.
I canโ€™t find it. When I look into the fig object, it still contains the initial values.
From this post (How do I get the camera rotation angles from the โ€œeyeโ€?) I understand the scene object is accessible in pure JS.

Has somebody managed to do that in the notebook ?
Any pointers ?


Hi there,
You can set the camera position programatically in your notebook with the parameters described here:
We donโ€™t have an example setting these via an ipython widget at the moment, though using those parameters would be a good place to start.

Indeed, your example shows how to position the camera programmatically.
But how do I do to get a handler of an existing 3d plot in a notebook, get the camera position, change it a bit, and update the plot ?
This is what I canโ€™t do.
Is it possible ?



Did you figure this out? I have a similar question.

I was looking for a solution as well and finally I solved it using Dash (inside a Jupyter notebook or just Python). You do not get the data inside the Jupyter Notebook, but an extra Tab (

Example code:

import plotly.graph_objects as go
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

fig = go.Figure(
        x = [1,2,3,4,5],
        y = [1,2,3,4,5],
        z = [[0, 1, 0, 1, 0],
             [1, 0, 1, 0, 1],
             [0, 1, 0, 1, 0],
             [1, 0, 1, 0, 1],
             [0, 1, 0, 1, 0]]

app = dash.Dash()
app.layout = html.Div([
    html.Div(id="output"),        # use to print current relayout values
    dcc.Graph(id="fig", figure=fig)

    Output("output", "children"),
    Input("fig", "relayoutData")
def show_data(data):
    # show camera settings like eye upon change
    return [str(data)]

app.run_server(debug=False, use_reloader=False)

Results in:
Screenshot 2021-04-16 164258