pyecharts繪制時間輪播圖柱形圖+餅圖+玫瑰圖+折線圖
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)])),
'大潤發(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('大潤發(fā)', data['大潤發(fā)'][i])
.set_global_opts(title_opts=opts.TitleOpts("{}年營業(yè)額".format(i)))
)
tl.add(bar, "{}年".format(i))
return tl
timeline_bar().render("timeline_bar.html")
2、pyecharts繪制時間輪播餅圖
#導(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í)", "娛樂", "休息", "運動", "交流"]
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)) #主題風(fēng)格
.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")) # 設(shè)置標(biāo)題
.set_series_opts(label_opts=opts.LabelOpts(formatter=':wppm3vysvbp%'))) # 顯示百分比
tl.add(c, "{}".format(i))
return tl
timeline_pie1().render("timeline_pie.html")
3、pyecharts繪制時間輪播玫瑰圖
#導(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í)", "娛樂", "休息", "運動", "交流"]
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)) #主題風(fēng)格
.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")) # 設(shè)置標(biāo)題
.set_series_opts(label_opts=opts.LabelOpts(formatter=':wppm3vysvbp%'))) # 顯示百分比
tl.add(c, "{}".format(i))
return tl
timeline_bar1().render("玫瑰圖.html")
4、pyecharts繪制時間輪播折線圖
#導(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í)','娛樂','休息','運動','交流'],
'時長': 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("{}年活動時長統(tǒng)計".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")
到此這篇關(guān)于pyecharts繪制時間輪播圖柱形圖+餅圖+玫瑰圖+折線圖的文章就介紹到這了,更多相關(guān)pyecharts繪制輪播圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
人工智能——K-Means聚類算法及Python實現(xiàn)
這篇文章主要介紹了人工智能——K-Means聚類算法及Python實現(xiàn),一個能夠找到我圈出的這?些點集的算法,就被稱為聚類算法,下面就來看看文章具體的介紹吧2022-01-01
python [:3] 實現(xiàn)提取數(shù)組中的數(shù)
今天小編就為大家分享一篇python [:3] 實現(xiàn)提取數(shù)組中的數(shù),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
pycharm執(zhí)行python時,填寫參數(shù)的方法
今天小編就為大家分享一篇pycharm執(zhí)行python時,填寫參數(shù)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-10-10
Python實現(xiàn)簡單生成驗證碼功能【基于random模塊】
這篇文章主要介紹了Python實現(xiàn)簡單生成驗證碼功能,結(jié)合實例形式分析了Python基于random模塊生成隨機字符串的相關(guān)操作技巧,需要的朋友可以參考下2018-02-02
python學(xué)習(xí)數(shù)據(jù)結(jié)構(gòu)實例代碼
數(shù)據(jù)結(jié)構(gòu)就是用來將數(shù)據(jù)組織在一起的結(jié)構(gòu)。換句話說,數(shù)據(jù)結(jié)構(gòu)是用來存儲一系列關(guān)聯(lián)數(shù)據(jù)的東西。在Python中有四種內(nèi)建的數(shù)據(jù)結(jié)構(gòu),分別是List、Tuple、Dictionary以及Set。本文將通過實例來介紹這些數(shù)據(jù)結(jié)構(gòu)的用法。2015-05-05
在spyder IPython console中,運行代碼加入?yún)?shù)的實例
這篇文章主要介紹了在spyder IPython console中,運行代碼加入?yún)?shù)的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04

