Skip to content

Instantly share code, notes, and snippets.

@saliksyed
Created July 10, 2017 21:40
Show Gist options
  • Save saliksyed/2570c69c660d7b5987492f19b88af0e4 to your computer and use it in GitHub Desktop.
Save saliksyed/2570c69c660d7b5987492f19b88af0e4 to your computer and use it in GitHub Desktop.
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import json
# create new figure, axes instances.
# we specify specific sizes for the figure to make it bigger
# DPI is "Dots per inch" -- it's used in the printing world
# The reason we specify the DPI instead of raw pixels is because
# we want the text to be consistently scaled.
my_dpi = 75
fig = plt.figure(figsize=(3600/my_dpi, 1800/my_dpi), dpi=my_dpi)
m = Basemap()
m.drawcoastlines()
data = json.loads(open("africa_china_airports.json","r").read())
lats = []
lons = []
for airport_id in data:
if data[airport_id]["country"] == "China":
lats.append(data[airport_id]["latitude"])
lons.append(data[airport_id]["longitude"])
# add scatter points for China only to the graph
m.scatter(lons, lats, latlon=True, marker="D",color="r")
lats = []
lons = []
populations = []
country_data= json.loads(open("africa_country_data.json","r").read())
for airport_id in data:
country = data[airport_id]["country"]
if country != "China":
lats.append(data[airport_id]["latitude"])
lons.append(data[airport_id]["longitude"])
populations.append(country_data[country]["population"])
# add scatter points for Africa only to the graph
m.scatter(lons, lats, latlon=True, marker="o",c=populations, cmap='coolwarm')
plt.savefig('map.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment