简体   繁体   中英

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:

在此处输入图像描述

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

在此处输入图像描述

How can I achieve the same result with code eg 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.

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 .

在此处输入图像描述

在此处输入图像描述

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.

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM