python数据可视化

数据可视化


使用pyecharts

API文档

import math
from pyecharts import options as opts
from pyecharts.charts import Surface3D
from pyecharts.globals import ThemeType
from pyecharts.charts import Line3D
from pyecharts.charts import Page
from example.commons import Faker

my_init_opts = opts.InitOpts(width='50%', page_title='3D', height='400px', theme=ThemeType.LIGHT)


def surface3d_base() -> Surface3D:
    def surface3d_data():
        for t0 in range(-60, 60, 1):
            y = t0 / 60
            for t1 in range(-60, 60, 1):
                x = t1 / 60
                z = math.sin(x * math.pi) * math.sin(y * math.pi)
                yield [x, y, z]

    c = Surface3D(my_init_opts).add(
        "我是图例",
        list(surface3d_data()),
        xaxis3d_opts=opts.Axis3DOpts(type_="value"),
        yaxis3d_opts=opts.Axis3DOpts(type_="value"),
        grid3d_opts=opts.Grid3DOpts(width=100, height=100, depth=100),
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="叫啥好呢"),
        visualmap_opts=opts.VisualMapOpts(max_=3, min_=-3, range_color=Faker.visual_color),
    )
    return c


def line3d_base() -> Line3D:
    data = []
    for t in range(0, 25000):
        _t = t / 1000
        x = (1 + 0.25 * math.cos(75 * _t)) * math.cos(_t)
        y = (1 + 0.25 * math.cos(75 * _t)) * math.sin(_t)
        z = _t + 2.0 * math.sin(75 * _t)
        data.append([x, y, z])
    c = (
        Line3D(my_init_opts)
            .add(
            "俺也是图例",
            data,
            xaxis3d_opts=opts.Axis3DOpts(Faker.clock, type_="value"),
            yaxis3d_opts=opts.Axis3DOpts(Faker.week_en, type_="value"),
            grid3d_opts=opts.Grid3DOpts(width=100, height=100, depth=100),
        )
            .set_global_opts(
            visualmap_opts=opts.VisualMapOpts(
                max_=30, min_=0, range_color=Faker.visual_color
            ),
            title_opts=opts.TitleOpts(title="Line3D"),
        )
    )
    return c


page = Page(page_title='3d')
page.add(line3d_base(), surface3d_base())


path = r'C:\Users\Desktop\html\html0.html'
# surface3d_base().render(path=path)
# line3d_base().render(path=path)
page.render(path=path)
上一篇:ssm简易整合


下一篇:Myeclipse搭建SSM项目