如何居中绘制三维曲面图?

2024-10-02 00:22:00 发布

您现在位置:Python中文网/ 问答频道 /正文

用绘图法绘制一个交互式三维曲面(去吧。浮出水面),则生成的曲面不在原点居中。它在(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')

Tags: godatanpfig绘制surfacelayoutxx
1条回答
网友
1楼 · 发布于 2024-10-02 00:22:00

可以指定X轴和Y轴的范围,如下所示:

layout = go.Layout(xaxis=dict(range=[-5, 5]),
                   yaxis=dict(range=[-5, 5]))

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

^{pr2}$

输出:

Plotly surface plot with fixed axis range for X and Y

参见official Plotly examples

相关问题 更多 >

    热门问题