from pyecharts import options as opts
from pyecharts.charts import Surface3D
import numpy as np
import math # 导入math库# 创建一个3D对象
_surface3d = Surface3D()defsurface3D_data():for t0 inrange(-60,60,1):
y = t0 /60for t1 inrange(-60,60,1):
x = t1 /60
z = math.sin(x * np.pi)* math.sin(y * np.pi)# 使用math.sin()代替sin()yield[x, y, z]# Surface3D
_surface3d.add(
series_name="",
shading="realistic",
data=list(surface3D_data()),
xaxis3d_opts=opts.Axis3DOpts(type_="value"),
yaxis3d_opts=opts.Axis3DOpts(type_="value"),
grid3d_opts=opts.Grid3DOpts(width=100, height=40, depth=100),)# 在网页中渲染可视化图像
_surface3d.render('3D_Surface.html')
from pyecharts import options as opts
from pyecharts.charts import Scatter3D
from pyecharts.faker import Faker
import random
defscatter3d()-> Scatter3D:
data =[(random.randint(0,100), random.randint(0,100), random.randint(0,100))for _ inrange(80)]
c =(
Scatter3D(init_opts=opts.InitOpts(width="1600px", height="800px")).add("", data, grid3d_opts=opts.Grid3DOpts(width=100, height=100, depth=100)).set_global_opts(visualmap_opts=opts.VisualMapOpts(max_=100),
title_opts=opts.TitleOpts("Scatter3D-基本示例")))return c
scatter3d().render("3d_scatter_chart.html")