使用Python pygal模块绘制世界地图示例

Linux系统环境:Ubuntu 18.04 LTS

Python版本:Python 3.6.7

首先安装:pygal_maps_world

此时可以访问pygal.maps.world模块,并指定代码绘制国家

示例代码:

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('linuxidc.svg')


if __name__ == '__main__':

    word_country_map()
    one_country_map()

绘制图如下:

使用Python pygal模块绘制世界地图示例

使用Python pygal模块绘制世界地图示例

使用Python pygal模块绘制世界地图示例

Countries

import pygal.maps.world

如下图:

使用Python pygal模块绘制世界地图示例

指定某个国家的值:

import pygal.maps.world

如下图:

使用Python pygal模块绘制世界地图示例

Continents

获取洲地图

import pygal.maps.world

如下图:

使用Python pygal模块绘制世界地图示例

 

 

 

国家代码列表:

codeCountry
adAndorra
aeUnited Arab Emirates
afAfghanistan
alAlbania
amArmenia
aoAngola
aqAntarctica
arArgentina
atAustria
auAustralia
azAzerbaijan
baBosnia and Herzegovina
bdBangladesh
beBelgium
bfBurkina Faso
bgBulgaria
bhBahrain
biBurundi
bjBenin
bnBrunei Darussalam
boBolivia, Plurinational State of
brBrazil
btBhutan
bwBotswana
byBelarus
bzBelize
caCanada
cdCongo, the Democratic Republic of the
cfCentral African Republic
cgCongo
chSwitzerland
ciCote d’Ivoire
clChile
cmCameroon
cnChina
coColombia
crCosta Rica
cuCuba
cvCape Verde
cyCyprus
czCzech Republic
deGermany
djDjibouti
dkDenmark
doDominican Republic
dzAlgeria
ecEcuador
eeEstonia
egEgypt
ehWestern Sahara
erEritrea
esSpain
etEthiopia
fiFinland
frFrance
gaGabon
gbUnited Kingdom
geGeorgia
gfFrench Guiana
ghGhana
glGreenland
gmGambia
gnGuinea
gqEquatorial Guinea
grGreece
gtGuatemala
guGuam
gwGuinea-Bissau
gyGuyana
hkHong Kong
hnHonduras
hrCroatia
htHaiti
huHungary
idIndonesia
ieIreland
ilIsrael
inIndia
iqIraq
irIran, Islamic Republic of
isIceland
itItaly
jmJamaica
joJordan
jpJapan
keKenya
kgKyrgyzstan
khCambodia
kpKorea, Democratic People’s Republic of
krKorea, Republic of
kwKuwait
kzKazakhstan
laLao People’s Democratic Republic
lbLebanon
liLiechtenstein
lkSri Lanka
lrLiberia
lsLesotho
ltLithuania
luLuxembourg
lvLatvia
lyLibyan Arab Jamahiriya
maMorocco
mcMonaco
mdMoldova, Republic of
meMontenegro
mgMadagascar
mkMacedonia, the former Yugoslav Republic of
mlMali
mmMyanmar
mnMongolia
moMacao
mrMauritania
mtMalta
muMauritius
mvMaldives
mwMalawi
mxMexico
myMalaysia
mzMozambique
naNamibia
neNiger
ngNigeria
niNicaragua
nlNetherlands
noNorway
npNepal
nzNew Zealand
omOman
paPanama
pePeru
pgPapua New Guinea
phPhilippines
pkPakistan
plPoland
prPuerto Rico
psPalestine, State of
ptPortugal
pyParaguay
reReunion
roRomania
rsSerbia
ruRussian Federation
rwRwanda
saSaudi Arabia
scSeychelles
sdSudan
seSweden
sgSingapore
shSaint Helena, Ascension and Tristan da Cunha
siSlovenia
skSlovakia
slSierra Leone
smSan Marino
snSenegal
soSomalia
srSuriname
stSao Tome and Principe
svEl Salvador
sySyrian Arab Republic
szSwaziland
tdChad
tgTogo
thThailand
tjTajikistan
tlTimor-Leste
tmTurkmenistan
tnTunisia
trTurkey
twTaiwan (Republic of China)
tzTanzania, United Republic of
uaUkraine
ugUganda
usUnited States
uyUruguay
uzUzbekistan
vaHoly See (Vatican City State)
veVenezuela, Bolivarian Republic of
vnViet Nam
yeYemen
ytMayotte
zaSouth Africa
zmZambia
zwZimbabwe

相关推荐