Practice Problem - Map of temperatures over Germany

Using, you can get the measured temperatures for a large set of cities or weather stations:

In [5]:
import requests
import json

key = ''  # PUT YOUR KEY HERE

coord = ['47.','56.','5.','16.']   # A box around Germany (lat_min, lat_max, long_min, long_max). Note: Strings!
pt    = 'city'                     # Get the data from all cities within the box
s = ''
s = s + 'box/'+pt+'?bbox='
s = s + coord[2] + "," + coord[1] + "," # left top
s = s + coord[3] + "," + coord[0] + "," # right bottom
s = s + '10'                            # zoom factor
s = s + '&APPID='+key
r = requests.get(s)
data = json.loads(r.text)

Here data is a dictionary with a somewhat complicated structure, but by using your knowledge of python you should be able to figure out its structure and extract an array of longiture, an array of lattitude and an array of temperatures.

Plot these data with a scatter plot with symbol color indicating the temperature. Use also a color bar, and mark the axes of the plot appropriately.

Can you make the proportions of the plot (vertical vs. horizontal scale) correct, so that Germany is not squeezed or extended in north-south direction?

You can use the data/germany.txt file which gives the longitude and latitude of the borders of Germany, for plotting.


In [6]:
# your solution here