问题
看过了pyecharts的文档,照着add()方法给对应的变量;还让GPT给修正过(貌似没问题了),可是在vscode上仍然报错
代码如下:
import json
from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts,TitleOpts,LabelOpts
# 读取文件数据
f = open("E:/疫情.txt","r",encoding="UTF-8")
data = f.read()
# 关闭文件
f.close()
# 将字符串json转为python字典
data_dict = json.loads(data)
# 从字典中取出省份数据
province_data_list = data_dict["areaTree"][0]["children"]
# 组装每个省份和确诊人数为元组,并各个省的数据都封装如列表内
# data_list = []
data_list_name = []
data_list_confirm = []
for province_data in province_data_list:
province_data_name = province_data["name"]
province_data_confirm = province_data["total"]["confirm"]
# data_list.append((province_data_name,province_data_confirm))
data_list_name.append(province_data_name)
data_list_confirm.append(province_data_confirm)
# print(type(data_list_name))
# 创建地图对象
map = Map()
# 添加数据
map.add("各省份确诊人数",data_list_name,data_list_confirm,maptype="china")
# 设置全局配置,定制分段的视觉映射
map.set_global_opts(
title_opts=TitleOpts(title="全国疫情地图",pos_left="center",pos_bottom="1%"),
visualmap_opts=VisualMapOpts(
is_show=True,
is_piecewise=True,
pieces=[
{"min":100,"max":999,"label":"1-9","color":"#98FB98"}
# {min:10,max:99,"label":"10-99","color":"#00FF7F"},
# {min:100,max:999,"label":"100-999","color":"#7CFC00"},
# {min:1000,max:4999,"label":"1000-4999","color":"#00FF00"},
# {min:5000,max:9999,"label":"5000-9999","color":"#7FFF00"},
# {min:10000,"label":"10000+","color":"#00FA9A"}
]
)
)
# 绘图
map.render("全国疫情地图可视化.html")
运行报错截图
按照提示,我删除了_maptype=_,但还是报错
这是我第一次发博客,可读性不是很高,请谅解