您好,登錄后才能下訂單哦!
本篇內容介紹了“怎么使用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")
#導入模塊 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}:aegqsqibtmh%'))) # 顯示百分比 tl.add(c, "{}".format(i)) return tl timeline_pie1().render("timeline_pie.html")
#導入模塊 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}:aegqsqibtmh%'))) # 顯示百分比 tl.add(c, "{}".format(i)) return tl timeline_bar1().render("玫瑰圖.html")
#導入模塊 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")
“怎么使用pyecharts繪制時間輪播圖”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。