Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing cartograms with Matplotlib?

In case somebody doesn't know: A cartogram is a type of map where some country/region-dependent numeric property scales the respective regions so that that property's density is (close to) constant. An example is

Example cartogram

from worldmapper.org. In this example, countries are scaled according to their population, resulting in near-constant population density.

Needless to say, this is really cool. Does anyone know of a Matplotlib-based library for drawing such maps? The method used at worldmapper.org is described in (1), so it would surprise me if no one has implemented this yet...

I'm also interested in hearing about other cartogram libraries, even if they're not made for Matplotlib.

(1) Michael T. Gastner and M. E. J. Newman, Diffusion-based method for producing density-equalizing maps, Proc. Nat. Acad. Sci. USA, 101, 7499-7504 (2004). Available at arXiv.

like image 235
gspr Avatar asked Nov 18 '10 16:11

gspr


2 Answers

There's this, though it's based and a different algorithm (and though it's on the ESRI site, it doesn't require ArcGIS). Of course, once you have the cartogram you can plot it in matplotlib.

like image 151
tom10 Avatar answered Nov 10 '22 11:11

tom10


Here is a Javascript plugin to make cartograms using D3. It is a good, simple solution if you are not too concerned about the regions being sized accurately. If accuracy is important, there are other options available that give you more freedom to play with the algorithm's parameters to get to a more accurate result.

Here are two great standalone programs I know of:

  • Scapetoad
  • Carto3F

Scapetoad is very easy to use. Just give it a shapefile, tell it which attribute to use for the scaling, and set a few accuracy parameters. If there is any doubt, this post describes the process.

Carto3F is more complex and allows for greater accuracy, though it is a bit trickier to figure out - lots of parameter settings without much documentation explaining them.

There is also a QGIS cartogram plugin, written in Python. Though I have not been able to get it to work, so cannot comment on that one.

like image 44
mgalka Avatar answered Nov 10 '22 09:11

mgalka