导入库。
from pyecharts.charts import Bar, Line, Map, Pie, Page
import pyecharts.options as opts
import time
绘制条形图(可缩放,可滑动)。
foreignBar = (
Bar()
.add_xaxis(foreign_name[:100])
.add_yaxis('确诊数', foreign_total_confirm[:100])
.add_yaxis('治愈', foreign_total_heal[:100])
.add_yaxis('死亡数', foreign_total_dead[:100])
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(title_opts=opts.TitleOpts(title="国外疫情确诊Top100", subtitle=f"数据来源:腾讯新闻 截止至{today}"),
datazoom_opts=opts.DataZoomOpts(type_="slider")
)
)
foreignBar.render_notebook()
结果:
绘制饼图
(
Pie()
.add("确诊数", data_pair=[(i, j) for i, j in zip(foreign_name[:10], foreign_total_confirm[:10])], rosetype='radius')
).render_notebook()
热力地图
chinaMap = (
Map()
# .add("累计确诊", maptype="world")
.add("累计确诊", [list(z) for z in zip(province_name, province_total_confirm)], maptype="china")
.set_global_opts(
title_opts=opts.TitleOpts(title="中国累计确诊数据", subtitle=f"数据来源:腾讯新闻 截止至{today}"),
visualmap_opts=opts.VisualMapOpts(
is_piecewise=True,
pieces=[{"max": 0, "label": '0人'},
{"min": 1, "max": 9, "label": '1-9人'},
{"min": 10, "max": 99, "label": '10-99人'},
{"min": 100, "max": 499, "label": '100-499人'},
{"min": 500, "max": 999, "label": '500-999人'},
{"min": 1000, "max": 9999, "label": '1000-9999人'},
{"min": 10000, "label": '10000人及以上'}]
)
)
)
chinaMap.render_notebook()
保存(html格式,html中的图片可以随意拖动)
page = Page(layout=Page.DraggablePageLayout)
page.add(
foreignBar,
chinaLine,
chinaMap,
chinaAbsPie
)
page.render('E:/桌面/中国疫情数据.html')