如何将Plotly的3D曲面图居中显示?

3
尝试使用plotly (go.Surface)绘制交互式3D曲面,结果曲面未居中于原点。它居中于(10,10),轴从0到20。我希望它居中于原点,轴被限制在-5到5之间。如果有人能帮助我做到这一点就太好了。

enter image description here

x = np.arange(-5,5,0.01)
y = np.arange(-5,5,0.01)
xx,yy=np.meshgrid(x,y)
Z=xx**2+yy**2

data = [go.Surface(z=Z.tolist(), colorscale='Viridis')]

layout = go.Layout(
...
code here
...
)

fig = dict(data=data, layout=layout)

plotly.offline.plot(fig, filename='pandas-3d-surface')
1个回答

2
您可以像这样指定 X 和 Y 轴的范围:
layout = go.Layout(xaxis=dict(range=[-5, 5]),
                   yaxis=dict(range=[-5, 5]))

请注意,这需要在数据中明确指定xy轴:

最初的回答。

data = [go.Surface(z=Z.tolist(), x=x, y=y, colorscale='Viridis')]

输出:

带有固定X和Y轴范围的Plotly表面图

请参阅官方Plotly示例


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接