pyecharts绘制时间轮播图(柱形图、饼图、玫瑰图、折线图)

2024-03-15 00:30

本文主要是介绍pyecharts绘制时间轮播图(柱形图、饼图、玫瑰图、折线图),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、pyecharts绘制时间轮播柱形图

from random import randint
from pyecharts import options as opts
from pyecharts.charts import Bar, Timeline
from pyecharts.globals import ThemeTypedata = {'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 tltimeline_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 ThemeTypeattr = ["学习", "娱乐", "休息", "运动", "交流"]
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 ThemeTypeattr = ["学习", "娱乐", "休息", "运动", "交流"]
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 ThemeTypelist1 = [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 tltimeline_bar().render("折线图.html")

在这里插入图片描述

这篇关于pyecharts绘制时间轮播图(柱形图、饼图、玫瑰图、折线图)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/810211

相关文章

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

Java中字符串转时间与时间转字符串的操作详解

《Java中字符串转时间与时间转字符串的操作详解》Java的java.time包提供了强大的日期和时间处理功能,通过DateTimeFormatter可以轻松地在日期时间对象和字符串之间进行转换,下面... 目录一、字符串转时间(一)使用预定义格式(二)自定义格式二、时间转字符串(一)使用预定义格式(二)自

Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码

《Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码》:本文主要介绍Java中日期时间转换的多种方法,包括将Date转换为LocalD... 目录一、Date转LocalDateTime二、Date转LocalDate三、LocalDateTim

golang获取当前时间、时间戳和时间字符串及它们之间的相互转换方法

《golang获取当前时间、时间戳和时间字符串及它们之间的相互转换方法》:本文主要介绍golang获取当前时间、时间戳和时间字符串及它们之间的相互转换,本文通过实例代码给大家介绍的非常详细,感兴趣... 目录1、获取当前时间2、获取当前时间戳3、获取当前时间的字符串格式4、它们之间的相互转化上篇文章给大家介

Feign Client超时时间设置不生效的解决方法

《FeignClient超时时间设置不生效的解决方法》这篇文章主要为大家详细介绍了FeignClient超时时间设置不生效的原因与解决方法,具有一定的的参考价值,希望对大家有一定的帮助... 在使用Feign Client时,可以通过两种方式来设置超时时间:1.针对整个Feign Client设置超时时间

springboot+dubbo实现时间轮算法

《springboot+dubbo实现时间轮算法》时间轮是一种高效利用线程资源进行批量化调度的算法,本文主要介绍了springboot+dubbo实现时间轮算法,文中通过示例代码介绍的非常详细,对大家... 目录前言一、参数说明二、具体实现1、HashedwheelTimer2、createWheel3、n

Java实现时间与字符串互相转换详解

《Java实现时间与字符串互相转换详解》这篇文章主要为大家详细介绍了Java中实现时间与字符串互相转换的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、日期格式化为字符串(一)使用预定义格式(二)自定义格式二、字符串解析为日期(一)解析ISO格式字符串(二)解析自定义

Java时间轮调度算法的代码实现

《Java时间轮调度算法的代码实现》时间轮是一种高效的定时调度算法,主要用于管理延时任务或周期性任务,它通过一个环形数组(时间轮)和指针来实现,将大量定时任务分摊到固定的时间槽中,极大地降低了时间复杂... 目录1、简述2、时间轮的原理3. 时间轮的实现步骤3.1 定义时间槽3.2 定义时间轮3.3 使用时

Python如何获取域名的SSL证书信息和到期时间

《Python如何获取域名的SSL证书信息和到期时间》在当今互联网时代,SSL证书的重要性不言而喻,它不仅为用户提供了安全的连接,还能提高网站的搜索引擎排名,那我们怎么才能通过Python获取域名的S... 目录了解SSL证书的基本概念使用python库来抓取SSL证书信息安装必要的库编写获取SSL证书信息

MySQL 日期时间格式化函数 DATE_FORMAT() 的使用示例详解

《MySQL日期时间格式化函数DATE_FORMAT()的使用示例详解》`DATE_FORMAT()`是MySQL中用于格式化日期时间的函数,本文详细介绍了其语法、格式化字符串的含义以及常见日期... 目录一、DATE_FORMAT()语法二、格式化字符串详解三、常见日期时间格式组合四、业务场景五、总结一、