python - 如何居中绘制 3d 曲面图?

标签 python plot plotly surface

尝试使用 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')

最佳答案

您可以像这样指定 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

关于python - 如何居中绘制 3d 曲面图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55942865/

相关文章:

R将传统情节和ggplot2放在一起

r - 在 ggplot/Plotly 中设置图例的 alpha

python - Plotly:在 jupyter 笔记本中以编程方式平移 3D 图形

r - Plotly - 如何更改直方图颜色?

python - 将 C++ 数组传递给 python

python - 在 django admin 中保存对象时出现 unicode 错误

python - 在 Python 中使用 pyqtgraph 进行多次更新图

python - Matplotlib:如何在缩放时缩放颤动图?

javascript - 在 jQuery.post 上,我收到消息 : The method GET is not allowed for the requested URL

python - mysql.connector.errors.ProgrammingError : 1064 (42000): You have an error in your SQL syntax; for the right syntax to use near ')' at line 1