您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“怎么使用pyecharts繪制時(shí)間輪播圖”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
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")
#導(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í)", "娛樂", "休息", "運(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=':mageg86%'))) # 顯示百分比 tl.add(c, "{}".format(i)) return tl timeline_pie1().render("timeline_pie.html")
#導(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í)", "娛樂", "休息", "運(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=':qoium4w%'))) # 顯示百分比 tl.add(c, "{}".format(i)) return tl timeline_bar1().render("玫瑰圖.html")
#導(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í)','娛樂','休息','運(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")
“怎么使用pyecharts繪制時(shí)間輪播圖”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。