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)])), '大潤發': 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")
2、pyecharts繪制時間輪播餅圖
#導入模塊 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}:{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 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}:{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 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繪制時間輪播圖柱形圖+餅圖+玫瑰圖+折線圖的文章就介紹到這瞭,更多相關pyecharts繪制輪播圖內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!
推薦閱讀:
- 以大熱劇《覺醒年代》為例用Python繪制可視化儀表盤
- 用python畫城市輪播地圖
- pyecharts繪制各種數據可視化圖表案例附效果+代碼
- Pyecharts 中Geo函數常用參數的用法說明
- 一文帶你掌握Pyecharts地理數據可視化的方法