使用 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()
运行效果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)