pyecharts绘制时间轮播图柱形图+饼图+玫瑰图+折线图
作者:"wink 时间:2022-01-18 13:19:47
1、pyecharts绘制时间轮播柱形图
from random import randint
from pyecharts import options as opts
from pyecharts.charts import Bar, Timeline
from pyecharts.globals import ThemeType
data = {'x': ['葡萄', '芒果', '草莓', '雪梨', '西瓜', '香蕉', '橙子'],
'沃尔玛': dict(zip(range(2010, 2020), [[randint(100, 1000) for fruit in range(7)] for year in range(10)])),
'大润发': dict(zip(range(2010, 2020), [[randint(100, 1000) for fruit in range(7)] for year in range(10)]))
}
def timeline_bar() -> Timeline:
x = data['x']
tl = Timeline(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
for i in range(2010, 2020):
bar = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
.add_xaxis(x)
.add_yaxis('沃尔玛', data['沃尔玛'][i])
.add_yaxis('大润发', data['大润发'][i])
.set_global_opts(title_opts=opts.TitleOpts("{}年营业额".format(i)))
)
tl.add(bar, "{}年".format(i))
return tl
timeline_bar().render("timeline_bar.html")
2、pyecharts绘制时间轮播饼图
#导入模块
from random import randint
from pyecharts import options as opts
from pyecharts.charts import Pie, Timeline
from pyecharts.globals import ThemeType
attr = ["学习", "娱乐", "休息", "运动", "交流"]
list1 = [2018, 2019, 2020, 2021, 2022]
list2 = [[randint(100, 1000) for time in range(7)] for year in range(5)] #嵌套列表
data = {'x': attr,
'时长': dict(zip(list1,list2))
}
def timeline_pie1() -> Timeline:
x = data['x']
tl = Timeline(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
for i in list1:
c = (
Pie(init_opts=opts.InitOpts(theme=ThemeType.WONDERLAND)) #主题风格
.add("", [list(z) for z in zip(attr,data['时长'][i])] )
.set_global_opts(title_opts=opts.TitleOpts(title="活动时长占比",pos_top="top",pos_left="left"),
legend_opts=opts.LegendOpts(pos_left="right", orient="vertical")) # 设置标题
.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{d}%'))) # 显示百分比
tl.add(c, "{}".format(i))
return tl
timeline_pie1().render("timeline_pie.html")
3、pyecharts绘制时间轮播玫瑰图
#导入模块
from random import randint
from pyecharts import options as opts
from pyecharts.charts import Pie, Timeline
from pyecharts.globals import ThemeType
attr = ["学习", "娱乐", "休息", "运动", "交流"]
list1 = [2018, 2019, 2020, 2021, 2022]
list2 = [[randint(100, 1000) for time in range(7)] for year in range(5)] #嵌套列表
data = {'x': attr,
'时长': dict(zip(list1, list2))
}
def timeline_bar1() -> Timeline:
x = data['x']
tl = Timeline(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
for i in list1:
c = (
Pie(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)) #主题风格
.add("", [list(z) for z in zip(attr,data['时长'][i])],radius=["25%", "75%"],rosetype="radius")
.set_global_opts(title_opts=opts.TitleOpts(title="活动时长占比",pos_top="top",pos_left="left"),
legend_opts=opts.LegendOpts(pos_left="right", orient="vertical")) # 设置标题
.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{d}%'))) # 显示百分比
tl.add(c, "{}".format(i))
return tl
timeline_bar1().render("玫瑰图.html")
4、pyecharts绘制时间轮播折线图
#导入模块
from random import randint
from pyecharts import options as opts
from pyecharts.charts import Line, Timeline
from pyecharts.globals import ThemeType
list1 = [2018, 2019, 2020, 2021, 2022]
list2 = [[randint(100, 1000) for time in range(7)] for year in range(5)] #嵌套列表
data = {'x': ['学习','娱乐','休息','运动','交流'],
'时长': dict(zip(list1, list2))
}
def timeline_bar() -> Timeline:
x = data['x']
tl = Timeline()
for i in list1:
bar = (
Line()
.add_xaxis(x)
.add_yaxis('时长(min)', data['时长'][i])
.set_global_opts(title_opts=opts.TitleOpts("{}年活动时长统计".format(i)))
)
tl.add(bar, "{}年".format(i))
# tl.add_schema(play_interval=1200, #播放速度
# is_timeline_show=False, #是否显示 timeline 组件
# is_auto_play=True)
return tl
timeline_bar().render("折线图.html")
来源:https://w1174.blog.csdn.net/article/details/125223049
标签:pyecharts,绘制,轮播图,柱形图,饼图,玫瑰图,折线图
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中的内置函数isdigit()
2023-05-16 16:10:31
ASP 日期的加减运算实现代码
2011-03-08 10:47:00
深入了解SQL Server 2008 商业智能平台
2009-01-15 13:03:00
用VBS语言实现的网页计算器源代码
2007-12-26 17:09:00
![](https://img.aspxhome.com/file/UploadPic/200712/26/20071226172731580s.jpg)
php之redis短线重连案例讲解
2023-06-12 13:16:04
Python中无限循环需要什么条件
2023-03-28 09:05:14
在ASP处理程序时,进度显示
2008-08-04 13:27:00
Python面向对象编程(一)
2023-04-27 15:02:13
Django中modelform组件实例用法总结
2023-09-28 14:35:49
![](https://img.aspxhome.com/file/2023/2/63222_0s.png)
CSS框架的相关汇总(CSS Frameworks)
2008-04-02 12:00:00
理解Python数据离散化手写if-elif语句与pandas中cut()方法实现
2023-02-24 10:33:33
大容量SQL Server数据库迁移偏方
2011-05-05 08:18:00
web 2.0设计指导之一:简单[译]
2008-10-12 09:37:00
![](https://img.aspxhome.com/file/UploadPic/200810/12/2008101294213567.jpg)
20行python代码的入门级小游戏的详解
2023-07-15 01:25:31
python接口调用已训练好的caffe模型测试分类方法
2021-08-11 18:31:04
![](https://img.aspxhome.com/file/2023/7/70107_0s.jpg)
Python 的Json 模块编码详解
2023-03-19 08:29:15
浅谈python中scipy.misc.logsumexp函数的运用场景
2023-11-10 17:10:56
设计表单的标签和输入区
2009-04-27 16:16:00
![](https://img.aspxhome.com/file/UploadPic/20094/27/01-64s.gif)
CI框架出现mysql数据库连接资源无法释放的解决方法
2023-11-15 07:13:35
注册表单的规则——读《Patterns for Sign Up &Ramp Up》
2008-07-17 12:51:00