Hellvetia
Hellvetia

Reputation: 345

Plotly: Panning 3D figure programmatically in jupyter notebook

I can't figure out how to pan my Plotly image using code.

I run the following code

# Creating the plot

import plotly.graph_objects as go

surface = go.Surface(x=AddOnMesh, y=CMesh, z=Matrix)
data = [surface]

layout = go.Layout(
    title='Depiction of the SA-CCR multiplier function',
    scene=dict(
        xaxis=dict(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)',
            autorange='reversed'

        ),
        yaxis=dict(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        zaxis=dict(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        xaxis_title = 'AddOn / V',
        yaxis_title = 'C / V',
        zaxis_title = 'Multiplier',
    )
)

fig = go.Figure(data=data, layout=layout)
fig.show()

This yields the following image:

enter image description here

As you can see the bottom is cut off. By manually panning it slightly up I can get it to look like this:

enter image description here

How can I achieve the same result with code e.g. by altering the Layout I am using. Manual adjustment is not an option as I directly convert the image with fig.to_image() in the next step.

Upvotes: 2

Views: 397

Answers (2)

Hellvetia
Hellvetia

Reputation: 345

In my case, the center parameter of the 3D camera controls yielded what I wanted.

camera = dict(
    center=dict(x=0, y=0, z=-0.1)
    )
fig = go.Figure(data=data, layout=layout)
fig.update_layout(scene_camera=camera)
fig.show()

Upvotes: 3

vestland
vestland

Reputation: 61234

You can freely change the camera position by editing the eye parameter in:

camera = dict(eye=dict(x=2, y=2, z=0.1))

fig.update_layout(scene_camera=camera)

You can lower the view point by setting z to a smaller value. Thie figures below compares z=1.5 to z=0.1.

enter image description here

enter image description here

I hope this turns out well with your dataset. If not, then please provide a sample of your data and I'll have another look.

Upvotes: 2

Related Questions