以下是使用 Pyecharts 制作世界地图、全国地图、江苏省地图和苏州市地图的示例代码和效果图:

  1. 世界地图

代码:

from pyecharts.charts import Map
from pyecharts import options as opts

data = [('Afghanistan', 2), ('Albania', 2), ('Algeria', 2), ('Angola', 2), ('Argentina', 3), ('Armenia', 2), ('Australia', 1), ('Austria', 1), ('Azerbaijan', 2), ('Bahrain', 2), ('Bangladesh', 2), ('Belarus', 1), ('Belgium', 1), ('Belize', 3), ('Benin', 2), ('Bhutan', 2), ('Bolivia', 3), ('Bosnia and Herzegovina', 2), ('Botswana', 2), ('Brazil', 3), ('Brunei Darussalam', 1), ('Bulgaria', 1), ('Burkina Faso', 2), ('Burundi', 2), ('Cambodia', 2), ('Cameroon', 2), ('Canada', 1), ('Cape Verde', 2), ('Central African Republic', 2), ('Chad', 2), ('Chile', 3), ('China', 2), ('Colombia', 3), ('Comoros', 2), ('Congo', 2), ('Costa Rica', 3), ('Croatia', 1), ('Cuba', 3), ('Cyprus', 1), ('Czech Republic', 1), ('Denmark', 1), ('Djibouti', 2), ('Dominica', 3), ('Dominican Republic', 3), ('Ecuador', 3), ('Egypt', 2), ('El Salvador', 3), ('Equatorial Guinea', 2), ('Eritrea', 2), ('Estonia', 1), ('Ethiopia', 2), ('Fiji', 1), ('Finland', 1), ('France', 1), ('Gabon', 2), ('Gambia', 2), ('Georgia', 2), ('Germany', 1), ('Ghana', 2), ('Greece', 1), ('Grenada', 3), ('Guatemala', 3), ('Guinea', 2), ('Guinea-Bissau', 2), ('Guyana', 3), ('Haiti', 3), ('Honduras', 3), ('Hungary', 1), ('Iceland', 1), ('India', 2), ('Indonesia', 2), ('Iran, Islamic Republic of', 2), ('Iraq', 2), ('Ireland', 1), ('Israel', 2), ('Italy', 1), ('Jamaica', 3), ('Japan', 1), ('Jordan', 2), ('Kazakhstan', 2), ('Kenya', 2), ('Kiribati', 1), ('Korea, Democratic People's Republic of', 2), ('Korea, Republic of', 1), ('Kuwait', 2), ('Kyrgyzstan', 2), ('Lao People's Democratic Republic', 2), ('Latvia', 1), ('Lebanon', 2), ('Lesotho', 2), ('Liberia', 2), ('Libya', 2), ('Lithuania', 1), ('Luxembourg', 1), ('Madagascar', 2), ('Malawi', 2), ('Malaysia', 2), ('Maldives', 2), ('Mali', 2), ('Malta', 1), ('Marshall Islands', 1), ('Mauritania', 2), ('Mauritius', 2), ('Mexico', 3), ('Micronesia, Federated States of', 1), ('Moldova, Republic of', 2), ('Monaco', 1), ('Mongolia', 2), ('Montenegro', 2), ('Morocco', 2), ('Mozambique', 2), ('Myanmar', 2), ('Namibia', 2), ('Nauru', 1), ('Nepal', 2), ('Netherlands', 1), ('New Zealand', 1), ('Nicaragua', 3), ('Niger', 2), ('Nigeria', 2), ('Norway', 1), ('Oman', 2), ('Pakistan', 2), ('Palau', 1), ('Panama', 3), ('Papua New Guinea', 1), ('Paraguay', 3), ('Peru', 3), ('Philippines', 2), ('Poland', 1), ('Portugal', 1), ('Qatar', 2), ('Republic of Kosovo', 2), ('Romania', 1), ('Russian Federation', 2), ('Rwanda', 2), ('Saint Kitts and Nevis', 3), ('Saint Lucia', 3), ('Saint Vincent and the Grenadines', 3), ('Samoa', 1), ('San Marino', 1), ('Sao Tome and Principe', 2), ('Saudi Arabia', 2), ('Senegal', 2), ('Serbia', 2), ('Seychelles', 2), ('Sierra Leone', 2), ('Singapore', 1), ('Slovakia', 1), ('Slovenia', 1), ('Solomon Islands', 1), ('Somalia', 2), ('South Africa', 2), ('South Sudan', 2), ('Spain', 1), ('Sri Lanka', 2), ('Sudan', 2), ('Suriname', 3), ('Swaziland', 2), ('Sweden', 1), ('Switzerland', 1), ('Syrian Arab Republic', 2), ('Taiwan, Province of China', 2), ('Tajikistan', 2), ('Tanzania, United Republic of', 2), ('Thailand', 2), ('Timor-Leste', 2), ('Togo', 2), ('Tonga', 1), ('Trinidad and Tobago', 3), ('Tunisia', 2), ('Turkey', 2), ('Turkmenistan', 2), ('Tuvalu', 1), ('Uganda', 2), ('Ukraine', 2), ('United Arab Emirates', 2), ('United Kingdom', 1), ('United States', 1), ('Uruguay', 3), ('Uzbekistan', 2), ('Vanuatu', 1), ('Venezuela, Bolivarian Republic of', 3), ('Viet Nam', 2), ('Yemen', 2), ('Zambia', 2), ('Zimbabwe', 2)]

map_chart = Map()
map_chart.set_global_opts(title_opts=opts.TitleOpts(title='世界地图'))
map_chart.add('世界地图', data, maptype='world')
map_chart.render('world_map.html')

效果图:

世界地图

  1. 全国地图

代码:

from pyecharts.charts import Map
from pyecharts import options as opts

data = [('北京', 1), ('天津', 2), ('上海', 3), ('重庆', 4), ('河北', 5), ('河南', 6), ('云南', 7), ('辽宁', 8), ('黑龙江', 9), ('湖南', 10), ('安徽', 11), ('山东', 12), ('新疆', 13), ('江苏', 14), ('浙江', 15), ('江西', 16), ('湖北', 17), ('广西', 18), ('甘肃', 19), ('山西', 20), ('内蒙古', 21), ('陕西', 22), ('吉林', 23), ('福建', 24), ('贵州', 25), ('广东', 26), ('青海', 27), ('西藏', 28), ('四川', 29), ('宁夏', 30), ('海南', 31), ('台湾', 32), ('香港', 33), ('澳门', 34)]

map_chart = Map()
map_chart.set_global_opts(title_opts=opts.TitleOpts(title='全国地图'))
map_chart.add('全国地图', data, maptype='china')
map_chart.render('china_map.html')

效果图:

全国地图

  1. 江苏省地图

代码:

from pyecharts.charts import Map
from pyecharts import options as opts

data = [('南京市', 1), ('苏州市', 2), ('无锡市', 3), ('常州市', 4), ('徐州市', 5), ('南通市', 6), ('连云港市', 7), ('淮安市', 8), ('盐城市', 9), ('扬州市', 10), ('镇江市', 11), ('泰州市', 12), ('宿迁市', 13)]

map_chart = Map()
map_chart.set_global_opts(title_opts=opts.TitleOpts(title='江苏省地图'))
map_chart.add('江苏省地图', data, maptype='江苏')
map_chart.render('jiangsu_map.html')

效果图:

江苏省地图

  1. 苏州市地图

代码:

from pyecharts.charts import Map
from pyecharts import options as opts

data = [('姑苏区', 1), ('相城区', 2), ('虎丘区', 3), ('吴中区', 4), ('吴江区', 5), ('苏州工业园区', 6), ('常熟市', 7), ('张家港市', 8), ('昆山市', 9), ('太仓市', 10)]

map_chart = Map()
map_chart.set_global_opts(title_opts=opts.TitleOpts(title='苏州市地图'))
map_chart.add('苏州市地图', data, maptype='苏州')
map_chart.render('suzhou_map.html')

效果图:

![苏州市地图](https://img-blog.csdnimg.cn/20220105101120762.png


原文地址: https://www.cveoy.top/t/topic/ogG7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录