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,绘制,轮播图,柱形图,饼图,玫瑰图,折线图
0
投稿
猜你喜欢
基于python实现名片管理系统
2023-02-03 12:33:50
在程序中压缩sql server2000的数据库备份文件的代码
2024-01-23 23:01:35
JavaScript 组件之旅(三):用 Ant 构建组件
2009-10-09 16:56:00
python实现马耳可夫链算法实例分析
2022-08-13 00:27:08
Python实现简单的学生信息管理系统
2021-06-19 10:59:44
5个Python杀手级的自动化脚本分享
2022-11-21 12:03:54
用python写一个福字(附完整代码)
2022-10-18 12:37:40
Django如何实现网站注册用户邮箱验证功能
2023-05-14 08:03:08
python通过exifread模块获得图片exif信息的方法
2023-08-18 05:00:15
python对常见数据类型的遍历解析
2022-01-18 21:24:28
Win10下安装CUDA11.0+CUDNN8.0+tensorflow-gpu2.4.1+pytorch1.7.0+paddlepaddle-gpu2.0.0
2022-05-08 19:29:32
显示日期格式的几个函数
2008-09-03 13:20:00
python抓取最新博客内容并生成Rss
2022-06-18 08:38:40
anaconda python3.8安装后降级
2021-09-12 05:28:51
Python利用3D引擎写一个Pong游戏
2021-09-13 15:56:58
详解Python GUI工具取色器
2021-01-23 10:12:04
利用Python第三方库xlrd读取Excel中数据实例代码
2023-02-17 05:28:58
Spring Boot整合 NoSQL 数据库 Redis详解
2024-01-29 18:16:36
Python word实现读取及导出代码解析
2021-05-11 07:56:47
HTTP状态码
2009-09-21 12:46:00