Ejemplo n.º 1
0
def create_cartogram(filename):
    """
    This function produces a cartogram map.
    """
    data_raw = gpd.read_file(filename)
    map = gplt.cartogram(data_raw,
                         projection=gcrs.Robinson(),
                         scale=data_raw['NUMPOINTS'],
                         hue=data_raw['NUMPOINTS'],
                         cmap='Reds',
                         k=5,
                         figsize=(30, 15)
                         )
    return map
Ejemplo n.º 2
0
import warnings


@pytest.fixture(scope="module")
def countries():
    return gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))


@pytest.mark.mpl_image_compare
@pytest.mark.parametrize("proj", [
    gcrs.PlateCarree(),
    gcrs.LambertCylindrical(),
    gcrs.Mercator(),
    gcrs.Miller(),
    gcrs.Mollweide(),
    gcrs.Robinson(),
    gcrs.Sinusoidal(),
    pytest.param(gcrs.InterruptedGoodeHomolosine(), marks=pytest.mark.xfail),
    pytest.param(gcrs.Geostationary(), marks=pytest.mark.xfail),
    gcrs.NorthPolarStereo(),
    gcrs.SouthPolarStereo(),
    gcrs.Gnomonic(),
    gcrs.AlbersEqualArea(),
    gcrs.AzimuthalEquidistant(),
    gcrs.LambertConformal(),
    gcrs.Orthographic(),
    gcrs.Stereographic(),
    pytest.param(gcrs.TransverseMercator(), marks=pytest.mark.xfail),
    gcrs.LambertAzimuthalEqualArea(),
    gcrs.WebMercator()
])
Ejemplo n.º 3
0
countries_gdf = countries_gdf.merge(SHDI_first, on='GDLCODE', how='left')
countries_gdf['shdi'].fillna(-1, inplace=True)
scheme = mapclassify.UserDefined(countries_gdf['shdi'],
                                 bins=[
                                     0, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6,
                                     0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 1.0
                                 ])

background_color = '#d1e5f0'
missing_color = 'grey'
fig, ax = plt.subplots(
    figsize=(20, 10),
    facecolor=background_color,
    subplot_kw={
        'projection': gcrs.Robinson(),
        # https://scitools.org.uk/cartopy/docs/latest/crs/projections.html
        'facecolor': background_color
    })
plt.title('Human Development Index by World Subdivisions',
          fontdict={
              'fontsize': 20,
              'fontweight': 'bold'
          })

cmap = plt.cm.get_cmap('Blues', len(scheme.bins) + 1)
cmap_list = [rgb2hex(cmap(i)) for i in range(cmap.N)]
cmap_list.insert(0, missing_color)
cmap_world = ListedColormap(cmap_list)

gplt.polyplot(
Ejemplo n.º 4
0
gdf = gdf.merge(df, on='name', how="left")
#print(gdf.info())

# ## Let's explore the total number of participants
# ### 2018 year:

# In[ ]:


df[['Foreign State', '2018_Total']].sort_values(by='2018_Total',ascending= False)

# In[ ]:


gplt.choropleth(gdf, hue=gdf['2018_Total'],projection=gcrs.Robinson(),
                cmap='Purples', linewidth=0.5, edgecolor='gray', 
                k=None, legend=True, figsize=(20, 8))
plt.title("Total number of participants in 2018")

# ### 2007 for comparision:

# In[ ]:


gplt.choropleth(gdf, hue=gdf['2007_Total'],projection=gcrs.Robinson(),
                cmap='Purples', linewidth=0.5, edgecolor='gray', 
                k=None, legend=True, figsize=(20, 8))
plt.title("Total number of participants in 2007")

# ## Number of winners