直接代码:
import pygal
from pygal_maps_world.i18n import COUNTRIES
def word_country_map():
"""世界各国"""
wm = pygal.maps.world.World()
wm.force_uri_protocol = 'http'
wm.title = "世界地图"
for code,name in COUNTRIES.items():
wm.add(name,code)
wm.add('Yemen',{'ye':'Yemem'})
wm.render_to_file('world_map.svg')
def one_country_map():
wm = pygal.maps.world.World()
wm.force_uri_protocol = 'http'
wm.title = '世界地图(一国)'
wm.add('North America', ['ca', 'mx', 'us'])
wm.render_to_file('americas_map.svg')
if __name__ == '__main__':
wm = pygal.maps.world.World()
wm.title = 'North,Central,and South America'
wm.add('North America', ['ca', 'mx', 'us'])
wm.add('Central America', ['bz', 'cr', 'gt', 'hn', 'ni', 'pa', 'sv'])
wm.add('South America', ['ar', 'bo', 'br', 'cl', 'co', 'ec', 'gf',
'gy', 'pe', 'py', 'sr', 'uy', 've'])
wm.render_to_file('americas.svg')
word_country_map()
one_country_map()
运行结果: