如何在散景中绘制参数化3D曲面

时间:2019-05-08 08:53:51

标签: bokeh

我想用散景绘制3d表面。我注意到我可以绘制z = f(x,y)之类的曲面,但无法绘制f(x,y,z)= 0之类的参数化曲面。在后者中,后者可以是闭合曲面。我感谢您的帮助。 这里以the link为例。我在此处包括了示例中所做的更改,而不是整个代码。

# parametric torus as an example in which the equation for the surface can be rephrased to be like f(x,y,z) = 0
angle = np.linspace(0, 2. * np.pi, 30)
theta, phi = np.meshgrid(angle, angle)
r, R = .25, 1.
xx = (R + r * np.cos(phi)) * np.cos(theta)
yy = (R + r * np.cos(phi)) * np.sin(theta)
xx = xx.ravel()
yy = yy.ravel()
value = r * np.sin(phi)
value = value.ravel()

# here is the original example which draw a surface like Z = f(x,y)
"""
x = np.arange(0, 300, 10)
y = np.arange(0, 300, 10)
xx, yy = np.meshgrid(x, y)
xx = xx.ravel()
yy = yy.ravel()
value = np.sin(xx / 50) * np.cos(yy / 50) * 50 + 50
"""

source = ColumnDataSource(data=dict(x=xx, y=yy, z=value))

surface = Surface3d(x="x", y="y", z="z", data_source=source)

show(surface)

1 个答案:

答案 0 :(得分:0)

首先必须明确指出:Bokeh没有任何内置的3d功能,3d也不为项目绘制优先级。您链接的示例首先是一个有关如何扩展Bokeh以集成第三方JavaScript库的示例。偶然地,为示例选择的库是vis.js Graph3d library。这是一个相当简单的3d库,据我所知,参数曲面完全超出了它的能力范围。要渲染这种表面,需要创建自己的新custom Bokeh extension,其中包含更复杂的3d JavaScript库(例如 three.js vtk.js 等) )。

相关问题