参考
数据可视化pyecharts使用
python爬虫之全国疫情数据可视化
利用Python实现新冠疫情数据可视化
python爬虫:新冠疫情累计确诊数据爬取及数据可视化
用pyecharts画地图
效果
疫情可视化数据地图
实现疫情可视化地图python代码
from datetime import date
import requests
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.globals import ThemeType
update_date = date.today()
# 1.疫情接口
url = "https://lab.isaaclin.cn/nCoV/api/area"
# 2.向url发请求,并将获取到的数据转换成json格式
resultJson = requests.get(url).json()
# 3.定义一个列表存储最终结果
province_data = []
# 4.只取国内数据
for item in resultJson['results']:
if item['countryName'] == "中国":
province_data.append(
[
item['provinceShortName'],
item['confirmedCount']
]
)
c = (
Map(init_opts=opts.InitOpts(theme=ThemeType.DARK))
.add("全国确诊人数", province_data, "china", is_map_symbol_show=False)
.set_global_opts(
title_opts=opts.TitleOpts(
title="新冠状病毒全国疫情地图",
subtitle="更新日期:{}".format(update_date),
),
# 视觉映射配置项
visualmap_opts=opts.VisualMapOpts(
is_show=True, # 是否显示
min_=0, # 左下角刻度最小值
max_=2000
)
)
.render("全国疫情可视化.html")
)
生成HTML文件
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Awesome-pyecharts</title>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/echarts.min.js"></script>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/maps/china.js"></script>
</head>
<body>
<div id="fe5046e1bcd04c87ba52713eceae039c" class="chart-container" style="width:900px; height:500px;"></div>
<script>
var chart_fe5046e1bcd04c87ba52713eceae039c = echarts.init(
document.getElementById('fe5046e1bcd04c87ba52713eceae039c'), 'dark', {
renderer: 'canvas'});
var option_fe5046e1bcd04c87ba52713eceae039c = {
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0,
"series": [
{
"type": "map",
"name": "\u5168\u56fd\u786e\u8bca\u4eba\u6570",
"label": {
"show": true,
"position": "top",
"margin": 8
},
"mapType": "china",
"data