3

I have a simple pandas DataFrame containing a list of European country names with a score value for each country. I want to display a map of Europe in a Jupyter notebook with each country colored according to that score. I want this map to be a simple, rendered image (not something dependent on, like, Google Maps). How could this be done?

import pandas as pd

df = pd.DataFrame(
         [
             ["Norway"     , 7.537],
             ["Denmark"    , 7.522],
             ["Switzerland", 7.494],
             ["Finland"    , 7.469],
             ["Netherlands", 7.377],
         ],
         columns = [
             "country",
             "score"
         ]
    )

I have searched for tools to do this but it is harder to find something robust than I would have expected. The nearest I have found is Vincent, but it appears to be unsupported now. It can be used in a way like the following:

import vincent
vincent.core.initialize_notebook()

geographic_data = [{
                      "name":    "states",
                      "url":     "https://raw.githubusercontent.com/wrobstory/vincent_map_data/master/us_states.topo.json",
                      "feature": "us_states.geo"
                  }]

vis = vincent.Map(
          geo_data   = geographic_data,
          scale      = 1000,
          projection = "albersUsa"
      )

vis.display()

What would be a good way to do this?

BlandCorporation
  • 1,324
  • 1
  • 15
  • 33

1 Answers1

1

Can try this:

import matplotlib.pyplot as plt
import cartopy
import cartopy.io.shapereader as shpreader
import cartopy.crs as ccrs

plt.figure(figsize=(26, 30))
ax = plt.axes(projection=ccrs.EuroPP())
ax.add_feature(cartopy.feature.BORDERS, linestyle='-', alpha=.5)
ax.coastlines(resolution='50m')
ax.add_feature(cartopy.feature.OCEAN,facecolor=(0.2,0.2,0.2))
ax.gridlines()
odo22
  • 590
  • 1
  • 7
  • 16