首先安装对应的python模块
$ pip install pyecharts
$ pip install echarts-countries-pypkg
$ pip install echarts-china-provinces-pypkg
$ pip install echarts-china-cities-pypkg
$ pip install echarts-china-counties-pypkg
世界地图
from pyecharts import options as optsfrom pyecharts.charts import Mapvalue = [95.1, 23.2, 43.3, 66.4, 88.5]country = ["China", "Canada", "Brazil", "Russia", "United States"]c = (Map().add("世界地图", [list(z) for z in zip(country, value)], "world").set_series_opts(label_opts=opts.LabelOpts(is_show=False)).set_global_opts(title_opts=opts.TitleOpts(title="Map-世界地图"),visualmap_opts=opts.VisualMapOpts(max_=200),).render("map_world.html"))
中国地图
from pyecharts import options as optsfrom pyecharts.charts import Mapprovince_distribution = {'河南省': 45.23, '北京市': 37.56, '河北省': 21, '辽宁省': 12, '江西省': 6, '上海省': 20,'安徽省': 10, '江苏省': 16, '湖南省': 9, '浙江省': 13, '海南省': 2, '广东省': 22, '湖北省': 8,'黑龙江省': 11, '陕西省': 11, '四川省': 7, '内蒙古': 3, '重庆市': 3, '云南省': 6, '贵州省': 2,'吉林省': 3, '山西省': 12, '山东省': 11, '福建省': 4, '青海省': 1, '天津市': 1}provinces = list(province_distribution.keys())values = list(province_distribution.values())c = (Map().add("中国地图", [list(z) for z in zip(provinces, values)], "china").set_series_opts(label_opts=opts.LabelOpts(is_show=False)).set_global_opts(title_opts=opts.TitleOpts(title="中国地图"),visualmap_opts=opts.VisualMapOpts(max_=200)).render("China_map.html"))
省市地图
from pyecharts import options as optsfrom pyecharts.charts import Mapcity = ['贵阳市', '六盘水市', '遵义市', '安顺市', '毕节市', '铜仁市', '黔西南布依族苗族自治州', '黔东南苗族侗族自治州', '黔南布依族苗族自治州']values = [1.07, 3.85, 6.38, 8.21, 2.53, 4.37, 9.38, 4.29, 6.1]c = (Map().add("贵州地图", [list(z) for z in zip(city, values)], "贵州").set_global_opts(title_opts=opts.TitleOpts(title="Map-贵州地图"), visualmap_opts=opts.VisualMapOpts(max_=10)).render("map_GuiZhou.html"))
区县地图
import pyecharts.options as optsfrom pyecharts.charts import Mapquxian = ['观山湖区', '云岩区', '南明区', '花溪区', '乌当区', '白云区', '修文县', '息烽县', '开阳县', '清镇市']values = [3, 5, 7, 8, 2, 4, 7, 8, 2, 4](Map().add(series_name="贵阳人口密度",maptype="贵阳",data_pair=[list(z)for z in zip(quxian,values)],# name_map=quxian,is_map_symbol_show=False,).set_global_opts(title_opts=opts.TitleOpts(title="贵阳人口密度 ()",# subtitle="人口密度数据来自Wikipedia",# subtitle_link=WIKI_LINK,),tooltip_opts=opts.TooltipOpts(trigger="item", formatter="{b}<br/>{c} (p / km2)"),visualmap_opts=opts.VisualMapOpts(min_=0,max_=10,range_text=["High", "Low"],is_calculable=True,range_color=["lightskyblue", "yellow", "orangered"],),).set_series_opts(label_opts=opts.LabelOpts(is_show=False)).render("GuiYang.html"))
飞行航线图
from pyecharts import options as optsfrom pyecharts.charts import Geofrom pyecharts.globals import ChartType, SymbolTypec = (Geo(init_opts=opts.InitOpts(bg_color="#000324")).add_schema(maptype="china",itemstyle_opts=opts.ItemStyleOpts(color="#323c48", border_color="#111"),).add("",[("广州", 55), ("兰州", 66), ("哈尔滨", 77), ("北京", 88), ("贵阳", 99), ("上海", 33), ("拉萨", 44), ("乌鲁木齐", 22)],type_=ChartType.EFFECT_SCATTER,itemstyle_opts=opts.ItemStyleOpts(),color="white").add("飞行航线图",[("贵阳", "上海"), ("贵阳", "北京"), ("贵阳", "广州"), ("贵阳", "哈尔滨"), ("贵阳", "拉萨"), ("贵阳", "乌鲁木齐"), ("贵阳", "兰州")],type_=ChartType.LINES,effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW, symbol_size=3, color="blue"),linestyle_opts=opts.LineStyleOpts(curve=0.2), color="red",).set_series_opts(label_opts=opts.LabelOpts(is_show=False)).set_global_opts(title_opts=opts.TitleOpts(title="飞行航线图", title_textstyle_opts=opts.TextStyleOpts(color="white")), # 设置标题及标题颜色legend_opts=opts.LegendOpts(textstyle_opts=opts.TextStyleOpts(color="white")) # 设置图例字体颜色).render("flay_lines.html"))
热力图
from pyecharts import options as optsfrom pyecharts.charts import Geofrom pyecharts.faker import Fakerfrom pyecharts.globals import ChartTypecity = ['贵阳市', '六盘水市', '遵义市', '安顺市', '毕节市', '铜仁市', '黔西南布依族苗族自治州', '黔东南苗族侗族自治州', '黔南布依族苗族自治州']values = [1.07, 3.85, 6.38, 8.21, 2.53, 4.37, 9.38, 4.29, 6.1]c = (Geo().add_schema(maptype="贵州").add("贵州热力图",[list(z) for z in zip(city, values)],type_=ChartType.HEATMAP,).set_series_opts(label_opts=opts.LabelOpts(is_show=False)).set_global_opts(visualmap_opts=opts.VisualMapOpts(max_=10, is_show=False), title_opts=opts.TitleOpts(title="贵州热力图")).render("geo_GuiZhou.html"))
如果觉得《Python基于Pyecharts 1.X的世界地图 省 市 县(区)地图 热力图和飞行航线图》对你有帮助,请点赞、收藏,并留下你的观点哦!