網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
1、pyecharts繪制時(shí)間輪播柱形圖
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)])),
'大潤(rùn)發(fā)': 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('大潤(rùn)發(fā)', data['大潤(rùn)發(fā)'][i])
.set_global_opts(title_opts=opts.TitleOpts("{}年?duì)I業(yè)額".format(i)))
)
tl.add(bar, "{}年".format(i))
return tl
timeline_bar().render("timeline_bar.html")
2、pyecharts繪制時(shí)間輪播餅圖
#導(dǎo)入模塊
from random import randint
from pyecharts import options as opts
from pyecharts.charts import Pie, Timeline
from pyecharts.globals import ThemeType
attr = ["學(xué)習(xí)", "娛樂(lè)", "休息", "運(yùn)動(dòng)", "交流"]
list1 = [2018, 2019, 2020, 2021, 2022]
list2 = [[randint(100, 1000) for time in range(7)] for year in range(5)] #嵌套列表
data = {'x': attr,
'時(shí)長(zhǎng)': 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)) #主題風(fēng)格
.add("", [list(z) for z in zip(attr,data['時(shí)長(zhǎng)'][i])] )
.set_global_opts(title_opts=opts.TitleOpts(title="活動(dòng)時(shí)長(zhǎng)占比",pos_top="top",pos_left="left"),
legend_opts=opts.LegendOpts(pos_left="right", orient="vertical")) # 設(shè)置標(biāo)題
.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:bsd5o550550j%'))) # 顯示百分比
tl.add(c, "{}".format(i))
return tl
timeline_pie1().render("timeline_pie.html")
3、pyecharts繪制時(shí)間輪播玫瑰圖
#導(dǎo)入模塊
from random import randint
from pyecharts import options as opts
from pyecharts.charts import Pie, Timeline
from pyecharts.globals import ThemeType
attr = ["學(xué)習(xí)", "娛樂(lè)", "休息", "運(yùn)動(dòng)", "交流"]
list1 = [2018, 2019, 2020, 2021, 2022]
list2 = [[randint(100, 1000) for time in range(7)] for year in range(5)] #嵌套列表
data = {'x': attr,
'時(shí)長(zhǎng)': 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)) #主題風(fēng)格
.add("", [list(z) for z in zip(attr,data['時(shí)長(zhǎng)'][i])],radius=["25%", "75%"],rosetype="radius")
.set_global_opts(title_opts=opts.TitleOpts(title="活動(dòng)時(shí)長(zhǎng)占比",pos_top="top",pos_left="left"),
legend_opts=opts.LegendOpts(pos_left="right", orient="vertical")) # 設(shè)置標(biāo)題
.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:bsd5o550550j%'))) # 顯示百分比
tl.add(c, "{}".format(i))
return tl
timeline_bar1().render("玫瑰圖.html")
4、pyecharts繪制時(shí)間輪播折線圖
#導(dǎo)入模塊
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': ['學(xué)習(xí)','娛樂(lè)','休息','運(yùn)動(dòng)','交流'],
'時(shí)長(zhǎng)': dict(zip(list1, list2))
}
def timeline_bar() -> Timeline:
x = data['x']
tl = Timeline()
for i in list1:
bar = (
Line()
.add_xaxis(x)
.add_yaxis('時(shí)長(zhǎng)(min)', data['時(shí)長(zhǎng)'][i])
.set_global_opts(title_opts=opts.TitleOpts("{}年活動(dòng)時(shí)長(zhǎng)統(tǒng)計(jì)".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
相關(guān)推薦
- 2022-11-12 Python?Multinomial?Naive?Bayes多項(xiàng)貝葉斯模型實(shí)現(xiàn)原理介紹_python
- 2022-04-07 C#實(shí)現(xiàn)單例模式的多種方式_C#教程
- 2022-06-07 教你使用.NET快速比較兩個(gè)byte數(shù)組是否相等_實(shí)用技巧
- 2022-10-15 淺談React?useDebounce?防抖原理_React
- 2022-12-19 C++?Boost?Fusion創(chuàng)建異構(gòu)容器詳解_C 語(yǔ)言
- 2022-06-22 C語(yǔ)言單值二叉樹(shù)真題講解_C 語(yǔ)言
- 2022-05-22 vscode調(diào)試container中的程序的方法步驟_相關(guān)技巧
- 2022-09-17 golang構(gòu)建工具M(jìn)akefile使用詳解_Golang
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支