Search code examples
pythonmatplotlibgeopandascartopy

How to plot maps with Python's matplotlib so that small island states are included too?


I have a basic setting for plotting data on the African map with Python matplotlib. Unfortunately the geopandas natural earth database does not include the small island states that would be essential to have included as well.

My basic setting is like this:

import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
africa = world.query('continent == "Africa"')

africa.plot(column="pop_est")
plt.show()

And the figure I get is like this: enter image description here

Instead, I would like to have a figure that is something like this, where small island states are neatly presented by visible dots: enter image description here

(The source of the figure is: https://en.wikipedia.org/wiki/African_Continental_Free_Trade_Area#/media/File:AfricanContinentalFreeTradeArea.svg)

There are two problems I have: 1) geopandas natural earth data do not include the island states, and 2) I don't know how to draw the otherwise invisible island states as visible dots.

I saw some related questions in SO for R, but it is specifically the Python solution that I am after.


Solution

  • I got a working solution by finding the centroid data for each country. I used R for that, based on this post: https://gis.stackexchange.com/a/232959/68457

    and made a GeoDataFrame that had a country identifier and geometry column for centroid points.

    Then I applied geopandas function buffer to the centroid points, i.e.:

       dfCentroids["geometry"] = dfCentroids.buffer(1)
    

    where 1 is the radius of the resulting spherical polygon. Then concatenating that with the geopandas naturalearth dataset, I got a geocoded data for plotting the map with dots on island states.