简体   繁体   English

Plotly:在 jupyter notebook 中以编程方式平移 3D 图

[英]Plotly: Panning 3D figure programmatically in jupyter notebook

I can't figure out how to pan my Plotly image using code.我不知道如何使用代码平移我的 Plotly 图像。

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.手动调整不是一个选项,因为我在下一步中直接使用fig.to_image()转换图像。

You can freely change the camera position by editing the eye parameter in:您可以通过编辑 eye 参数来自由更改相机 position

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.您可以通过将 z 设置为较小的值来降低视点。 Thie figures below compares z=1.5 to z=0.1 .下图将z=1.5z=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.就我而言, 3D 相机控件center参数产生了我想要的结果。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 jupyter 笔记本中使用 alphahull >0 和 plotly 显示 3d 网格时出现问题 - Problem to diplay a 3d mesh using alphahull >0 with plotly in jupyter notebook 在jupyter笔记本幻灯片中渲染交互式绘图 - Render interactive plotly figure in jupyter notebook slideshow 以编程方式停止 Jupyter 笔记本中特定图形的交互 - Programmatically Stop Interaction for specific Figure in Jupyter notebook 在Jupyter Notebook中使用Matplotlib对3D矩阵进行动画处理 - Animate a 3D matrix with Matplotlib in Jupyter Notebook 在Jupyter笔记本电脑的不同单元格中显示mayavi X3D图形 - Display mayavi X3D figure in different cells in Jupyter notebook 使用plotly在一张图中绘制多条3d线 - Plotting multiple 3d lines in one figure using plotly 如何用 3D Mesh Plotly 在 1 图中 plot 多于 1 个图? - How to plot more than 1 graph in 1 figure with 3D Mesh Plotly? 在 Plotly Express 中散布 3d - Colab Notebook 未在等轴上绘图 - Scatter 3d in Plotly Express - Colab Notebook is not plotting with equal axes VSCode 中 jupyter notebook 中的交互式 python 3d 绘图 - Interactive python 3d plot in jupyter notebook within VSCode 如何在 jupyter notebook 中放大交互式 3D plot - How to zoom on an interactive 3D plot in jupyter notebook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM