Linux 拨号vps windows公众号手机端

Bokeh怎么实现3D数据可视化

lewis 1年前 (2024-05-19) 阅读数 45 #程序编程
文章标签 Bokeh

要实现3D数据可视化的Bokeh,可以使用Bokeh的Surface3dScatter3d方法来创建3D表面图和散点图。

首先,导入必要的库和模块:

from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource

然后,创建一个Figure对象,并使用Surface3d方法来绘制3D表面图:

# 创建数据
x = [1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5]
z = [[1, 2, 3, 4, 5],
     [1, 2, 3, 4, 5],
     [1, 2, 3, 4, 5],
     [1, 2, 3, 4, 5],
     [1, 2, 3, 4, 5]]

# 创建数据源
source = ColumnDataSource(data=dict(
    x=x,
    y=y,
    z=z
))

# 创建3D表面图
plot = figure(title="3D Surface Plot", sizing_mode='stretch_both')
plot.add_layout(plot.toolbar)

plot.surface(x='x', y='y', z='z', source=source)

show(plot)

另外,你也可以使用Scatter3d方法来创建3D散点图:

# 创建数据
x = [1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5]
z = [1, 2, 3, 4, 5]

# 创建数据源
source = ColumnDataSource(data=dict(
    x=x,
    y=y,
    z=z
))

# 创建3D散点图
plot = figure(title="3D Scatter Plot", sizing_mode='stretch_both')
plot.add_layout(plot.toolbar)

plot.scatter(x='x', y='y', z='z', source=source)

show(plot)

通过以上步骤,你可以使用Bokeh实现3D数据可视化。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门