[英]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.5
与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.就我而言, 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.