pyecharts模塊實現數據可視化
這里采用疫情數據作為參考指標,繪畫可視化視圖。
1. 全球疫情累計死亡人數分布圖
示例功能代碼如下:
def yiqing_world(data): world_data = [] for item in data["results"]: if item["countryEnglishName"]: world_data.append([item["countryEnglishName"] .replace('United States of America', 'United States') .replace('United Kingdom', 'Greenland'), item["deadCount"]]) _max = max([item[1] for item in world_data]) world_map = ( Map(init_opts=opts.InitOpts(theme='romantic')) .add("累計死亡人數", world_data, 'world', is_map_symbol_show=False) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="全球疫情累計死亡人數分布圖", pos_left="left"), legend_opts=opts.LegendOpts(is_show=False), visualmap_opts=opts.VisualMapOpts(max_=_max, is_piecewise=True) ) ) world_map.render("全球疫情累計死亡人數分布圖.html")
2.中國疫情確診人數分布地圖
示例功能代碼如下:
def yiqing_china(data): china_data = [] for item in data["results"]: if item["countryName"] == "中國": china_data.append([item["provinceShortName"], item["confirmedCount"]]) _max = max([item[1] for item in china_data]) china_map = ( Map(init_opts=opts.InitOpts(theme='dark')) .add("確診人數", china_data, "china", is_map_symbol_show=False) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="中國疫情確診人數分布地圖"), legend_opts=opts.LegendOpts(is_show=True), visualmap_opts=opts.VisualMapOpts(max_=_max, is_piecewise=True) ) ) china_map.render("中國疫情確診人數分布地圖.html")
此外還有更多繪畫圖。
原文鏈接:https://www.jianshu.com/p/d0ec11363d2d