Skip to content

Ghana MultiMap Generator

Charles edited this page Jul 30, 2019 · 3 revisions

Resources

This guide refers to the scripts and content here: https://github.com/worldbank/GOST_PublicGoods/tree/master/Implementations/Ghana%20-%20MultiMap%20Generator

Credits

This is good old fashioned C.Fox engineering.

Objective

This script aims to generate a series of thumbnail maps which show broad-brush, non-detailed information on a country or regional scale for a range of variables, quickly. It is provided mainly as a code base to riff-off. In the end, it was not used for a proper operation, but to show various variables from the Ghana Business Census at once.

Inputs

  • A dataset to map, at an appropriate detail level (e.g. Admin Level 1, or regional data for a handful of countries)
  • A corresponding shapefile which matches this data.

N.B. If you have a shapefile with attribute columns already prepared, then you only need that. This script, however, was designed to join an Excel document on to a blank admin boundaries shapefile template.

Process

There is only one step / script in this process chain, and it is very straightforward. Users will find it fairly easy to follow along in the Jupyter Notebook directly.

The main complexity / 'gotcha' is in making sure that the data which the user wants to plot must have a key field which joins it easily to a polygonal shapefile with an identically named keyfield. This script is also not set up well to handle null / missing values, so some user-end data consistency checks are recommended.

In terms of generating the MatPlotLib object at the end, this is the key line:

fig, axes = plt.subplots(nrows = len(y_labels),
                         ncols = len(x_labels), 
                         figsize = (len(x_labels)*scale*figure_aspect, len(y_labels)*scale),
                        sharex = True, 
                        sharey = True)

nrows and ncols defines the number of sub-plots in the overall diagram - here, the length of the x and y axis labels. This could also be a standard numerical input. Figsize is also numerical, but here I am making it contingent on the number of plots, the figure aspect ratio, and a useful scaling factor. This can be played around with endlessly by the user, there is no right or wrong answer.

Call fig.save([path]) to save a .jpg or .png to file.

Sample Output