简体   繁体   English

需要帮助了解如何使用 plotly 对 3d 表面 plot

[英]Need help in understanding how to 3d surface plot using plotly

I am trying to plot a function z= sinx cosy over -pi to pi我正在尝试 plot 一个 function z= sinx 舒适超过 -pi 到 pi

This is what I'm hoping to get这是我希望得到的

Also shown like this也这样显示

This is the code I have written in an attempt to do the same:这是我编写的尝试做同样的代码:

import plotly.graph_objs as go
from scipy.linalg import toeplitz

x=np.linspace(-np.pi,np.pi,30)
z = [(np.sin(i)*np.cos(i)) for i in x]

fig = go.Figure(data=[go.Surface(x=x, y=x, z=toeplitz(z))])
fig.show()

plotly output that I'm getting我得到的 plotly output

I have not been able to understand what 'grid' or '2d array' format I have to convert my z co-ordinate column data into for getting the right graph.我无法理解我必须将 z 坐标列数据转换为什么“网格”或“二维数组”格式才能获得正确的图形。 Toeplitz was an attempt to do the same, but it seems symmetric unlike the required graph. Toeplitz 试图做同样的事情,但与所需的图不同,它看起来是对称的。 Please help请帮忙

I think I've got it, if you're facing similar issue you can refer/use the code below我想我明白了,如果您遇到类似的问题,您可以参考/使用下面的代码

import numpy as np
import plotly.graph_objs as go
f = lambda x,y: np.sin(x) * np.cos(y)
x = np.linspace(-np.pi, np.pi, 30)
y = np.linspace(-np.pi, np.pi, 30)
X,Y = np.meshgrid(x,y)
F = f(X,Y)

fig = go.Figure(data=[go.Surface(x=X, y=Y, z=F)])
fig.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM