Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choropleth maps for Germany

I am having Revenue data which I need to map on the German map.

My data contains the postcodes, the corresponding latitude and longitude, as well as the value of revenue corresponding to that postcode, something like this -

data = {'35447': {50.6022608,8.861908900000001,434224.45€}} 

I am using plotly Python library, which helps to create Choropleth/Point Maps. I referred to Pandas Choropleth Maps example, which explains how to use plotly, but for USA. In the example by setting

locationmode = 'USA-states'
locations = 'AL'# AL for Alabama, AZ for Arizona

we could create Choropleth maps for USA. Similarly, by setting

locationmode = 'USA-states'
lon = -74.25908989999999 # Longitude
lat = 40.4773991 # Latitude

we could create Point Maps for USA.

Question: How can we use library plotly to create Choropleth/Point maps for Germany? Or is it that plotly is only implemented for USA. pyGeoDb could have solved this problem, but it cannot be used for Python 3.+

As a side note, which may or may not be helpful - Choropleth maps are not implemented for zip codes and plotly confirms that.

like image 778
cph_sto Avatar asked Dec 10 '17 15:12

cph_sto


2 Answers

Well the fastest and simple solution to plot an interactive map with python is using bokeh. You can find more details in this article. The main idea is that you just need to find a geojson file of the country that you want plot and then the rest is pretty straightforward. You can find a geojson file for Germany (and many other countries) in this github repo.

The geojson file basically contains the coordinates of the borders of the corresponding territories, so that the schema is drawn. Since you have the longitude and latitude of the territories that you want to show you can just check in which polygon (State, Regierungsbezierk, Landkreis or Kreisfreie Stadt) they are contained.

I hope this helps.

like image 154
Letsios Matthaios Avatar answered Oct 24 '22 06:10

Letsios Matthaios


You can follow the Guide on how to plot images from Canada which is explained here:

Python: how to create a choropleth map out of a shapefile of Canada?

Afterwards, you need to replace the geo pandas shape file with German shapes. You can obtain these and add to geopandas as described here:

https://juanitorduz.github.io/germany_plots/

like image 32
Rene B. Avatar answered Oct 24 '22 04:10

Rene B.