如何居中绘制3D表面图?

时间:2019-05-01 21:22:22

标签: python plot plotly surface

尝试使用plotly(转到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 个答案:

答案 0 :(得分:0)

您可以像这样为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')]

输出:

Plotly surface plot with fixed axis range for X and Y

请参见official Plotly examples