(编辑:jimmy 日期: 2025/10/29 浏览:2)
我就废话不多说啦,还是直接看代码吧!
from example.commons import Faker
from pyecharts import options as opts
from pyecharts.charts import Bar3D
import random
def bar3d_base() -> Bar3D:
data = [(i, j, random.randint(0, 12)) for i in range(6) for j in range(24)]
c = (
Bar3D()
.add(
"",
[[d[1], d[0], d[2]] for d in data],
xaxis3d_opts=opts.Axis3DOpts(Faker.clock, type_="category"),
yaxis3d_opts=opts.Axis3DOpts(Faker.week_en, type_="category"),
zaxis3d_opts=opts.Axis3DOpts(type_="value"),
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(max_=20),
title_opts=opts.TitleOpts(title="Bar3D-基本示例"),
)
.render_notebook()
.render()
)
return c
bar3d_base()
在官网示例上加上这行就行了
.render_notebook()
补充知识:pyecharts 的 0.5x 版本和 1.x 版本
pyecharts 的 0.5x 版本和 1.x 版本有很大差异,支持的东西和文档都发生了变化。
有的时候甚至出现不兼容情况,比如 1.x 支持的 python 版本就比较新,旧的版本就不支持了。
pyecharts 0.5x 版本下载:
pip install pyecharts==0.5.11
pyecharts 1.x 版本(现在来看默认直接 pip 即可)
pip install pyecharts
以上这篇使用pyecharts在jupyter notebook上绘图就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。