使用Pyecharts制作Bar3D用法详解

使用Pyecharts制作Bar3D用法详解,第1张

使用Pyecharts制作Bar3D用法详解

        使用 Pyecharts 进行数据可视化时可提供直观、交互丰富、可高度个性化定制的数据可视化图表。

本文以pyecharts==1.9.1为例:

1.标准3D柱状图

示例代码:

import random
import pyecharts.options as opts
from pyecharts.charts import Bar3D

hours = ["12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p",
         "6p", "7p", "8p", "9p", "10p", "11p", ]
days = ["Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday"]

data = [(i, j, random.randint(0, 12)) for i in range(6) for j in range(24)]
data = [[d[1], d[0], d[2]] for d in data]

res = (
    Bar3D(init_opts=opts.InitOpts(width="900px", height="600px")).add(
        series_name="",
        data=data,
        xaxis3d_opts=opts.Axis3DOpts(type_="category", data=hours),
        yaxis3d_opts=opts.Axis3DOpts(type_="category", data=days),
        zaxis3d_opts=opts.Axis3DOpts(type_="value"),
    ).set_global_opts(
        title_opts=opts.TitleOpts("标准3D柱状图"),
        visualmap_opts=opts.VisualMapOpts(
            max_=20,
            range_color=[
                "#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf", "#fee090", "#fdae61", "#f46d43",
                "#d73027", "#a50026",
            ],
        )
    )
)
res.render_notebook()

运行结果:

 2.堆叠3D柱状图

示例代码:

import random
from pyecharts import options as opts
from pyecharts.charts import Bar3D

x_data = y_data = [i for i in range(10)]


def generate_data():
    data = []
    for j in range(10):
        for k in range(10):
            value = random.randint(0, 9)
            data.append([j, k, value * 2 + 4])
    return data


bar3d = Bar3D()
for _ in range(10):
    bar3d.add(
        "",
        generate_data(),
        shading="lambert",
        xaxis3d_opts=opts.Axis3DOpts(data=x_data, type_="value"),
        yaxis3d_opts=opts.Axis3DOpts(data=y_data, type_="value"),
        zaxis3d_opts=opts.Axis3DOpts(type_="value"),
    )
bar3d.set_global_opts(title_opts=opts.TitleOpts("堆叠3D柱状图"))
bar3d.set_series_opts(**{"stack": "stack"})
# bar3d.render("堆叠3D柱状图.html")
bar3d.render_notebook()

运行效果:

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5689982.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存