之前介绍过用pyecharts显示地图。下面先生成显示中国各省人口地图的网页。
from pyecharts import options as optsfrom pyecharts.charts import Map, Pagefrom pyecharts.faker import Collector, Fakerdef readData(path): populations = list() with open(path,"rt",encoding="utf8") as f:#读取中文文本文件 line = f.readline() while line: a = line[:-1].split("\t") populations.append([a[0],int(a[1])]) line = f.readline() return populationsC = Collector()@C.funcsdef map_visualmap() -> Map: c = ( Map() .add("中华人民共和国各省人口数(第6次人口普查)", populations, "china") .set_global_opts( title_opts=opts.TitleOpts(title="pyecharts 嵌入 PyQt5 DEMO"), visualmap_opts=opts.VisualMapOpts(max_=max_), ) ) return cpopulation