File:Infant-under-five-mortality-worldmap-2016.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(SVG file, nominally 1,620 × 774 pixels, file size: 468 KB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description
English: Number of deaths of infants under five years per 1,000 live births for 2016.

Data from https://data.worldbank.org/indicator/SH.DYN.MORT?end=2016&start=2016&view=map

Country shapes from http://www.naturalearthdata.com/downloads/110m-cultural-vectors

Created with Python and Matplotlib Basemap Toolkit.
Date
Source Own work
Author MagHoxpox
"""
Number of deaths of infants under five years per 1,000 live births for 2016. 
Data from https://data.worldbank.org/indicator/SH.DYN.MORT?end=2016&start=2016&view=map
Country shapes from http://www.naturalearthdata.com/downloads/110m-cultural-vectors/
Created with Python and Matplotlib Basemap Toolkit.
"""

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np

from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from matplotlib.patches import PathPatch
from matplotlib.colors import LinearSegmentedColormap

#########################################################################################
# read mortality data
data = open("API_SH.DYN.MORT_DS2_en_csv_v2/API_SH.DYN.MORT_DS2_en_csv_v2.csv").readlines()
mortality={}
for line in data[5:]:
    line = line.replace('",','|').replace(",","").replace('"',"").strip().split("|")
    if len(line)<10:
        continue
    try:
        value=float(line[-2])
    except:
        continue
    key = line[1]
    mortality[key]=value

#########################################################################################
# draw empty worldmap
fig = plt.figure(figsize=(18,8.6))
plt.subplots_adjust(left=0.01, bottom=0.01, right=1.12, top=0.99)

m = Basemap(projection='robin',lon_0=0, llcrnrlat=-60,urcrnrlat=85, llcrnrlon=-180, urcrnrlon=180, resolution='l')
m.drawmapboundary()


#########################################################################################
# color country shapes
m.readshapefile('ne_110m_admin_0_countries/ne_110m_admin_0_countries', name='world', drawbounds=True, color='gray')

countries = []
undefined_countries = []
mortList  = []
for info, shape in zip(m.world_info, m.world):
    try:
        mort = mortality[info["ADM0_A3"]]
    except:
        undefined_countries.append(Polygon(np.array(shape), True))
        continue

    countries.append(Polygon(np.array(shape), True))
    mortList.append(mort)
    
mortArray = np.array(mortList)
print mortArray.min(), mortArray.max()
ticks = np.linspace(0, 130,14)

#########################################################################################
# colorbar
cm = LinearSegmentedColormap.from_list("cm", ["#81fcff", "#19ff19", "#e2f000", "#ffaa31", "#ff8e51", "#ff6969", "#8c0000", "#3c0000"])
p = PatchCollection(countries, alpha=0.5,  zorder=3, cmap=cm)
p.set_array(mortArray)
p.set_clim([ticks.min(), ticks.max()])

plt.gca().add_collection(p)
cb = fig.colorbar(p, ticks = ticks, shrink=0.6, pad = 0.02)

#########################################################################################
# set countries without data to lightgray
p2 = PatchCollection(undefined_countries, alpha=0.5,  zorder=3, cmap=LinearSegmentedColormap.from_list("lg", ["lightgray", "lightgray"]))
p2.set_array(np.ones((len(undefined_countries),)))
plt.gca().add_collection(p2)

#########################################################################################
# save and show
filename = "infant-under-five-mortality-worldmap-2016"
plt.savefig(filename + ".svg")
plt.savefig(filename + "-1800px.png", dpi=100)
plt.savefig(filename + "-900px.png",  dpi=50)

plt.show()

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current10:12, 31 October 2017Thumbnail for version as of 10:12, 31 October 20171,620 × 774 (468 KB)MagHoxpox (talk | contribs)User created page with UploadWizard

The following page uses this file:

File usage on other wikis

The following other wikis use this file:

Metadata