How to use the geoplot.cartogram function in geoplot

To help you get started, we’ve selected a few geoplot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ResidentMario / geoplot / tests / input_tests.py View on Github external
def test_cartogram(self):
        try:
            gplt.cartogram(series_gaussian_polys, scale=list_hue_values)
            gplt.cartogram(dataframe_gaussian_polys, scale=list_hue_values)

            gplt.cartogram(dataframe_gaussian_polys, hue=list_hue_values, scale=list_hue_values)
            gplt.cartogram(dataframe_gaussian_polys, hue=series_hue_values, scale=list_hue_values)
            gplt.cartogram(dataframe_gaussian_polys, hue=map_hue_values(), scale=list_hue_values)
            gplt.cartogram(dataframe_gaussian_polys, hue='hue_var', scale=list_hue_values)
        finally:
            plt.close('all')
github ResidentMario / geoplot / tests / property_tests.py View on Github external
def test_cartogram(self, projection, scale_dataset, hue_vars, legend_vars, trace):
        kwargs = {'projection': projection, 'scale': scale_dataset, 'trace': trace}
        kwargs = {**kwargs, **hue_vars, **legend_vars}
        try: gplt.cartogram(gaussian_polys, **kwargs)
        finally: plt.close()
github ResidentMario / geoplot / tests / viz_tests.py View on Github external
    [cartogram, poly_df, {'scale': 'var', 'linewidth': 0, 'legend': True}],
    [cartogram, poly_df,
     {'scale': 'var', 'linewidth': 0, 'legend': True,
      'projection': AlbersEqualArea()}],
    [voronoi, p_df, {'facecolor': 'lightgray', 'edgecolor': 'white'}],
    [voronoi, p_df, 
     {'facecolor': 'lightgray', 'edgecolor': 'white',
      'projection': AlbersEqualArea()}],
    [quadtree, p_df, {'facecolor': 'lightgray', 'edgecolor': 'white'}],
    [quadtree, p_df, 
     {'facecolor': 'lightgray', 'edgecolor': 'white', 'projection': AlbersEqualArea()}],
    [sankey, ls_df, {'scale': 'var', 'legend': True}],
    [sankey, ls_df, {'scale': 'var', 'legend': True, 'projection': AlbersEqualArea()}]
])
def test_plot_basic(func, df, kwargs):
    return func(df, **kwargs).get_figure()
github ResidentMario / geoplot / tests / kwarg_tests.py View on Github external
def test_cartogram(self):
        try:
            gplt.cartogram(dataframe_gaussian_polys, scale='hue_var',
                           projection=gcrs.PlateCarree(), facecolor='white')

            gplt.cartogram(dataframe_gaussian_polys, scale='hue_var',
                           projection=gcrs.PlateCarree(), legend_kwargs={'fancybox': False})
        finally:
            plt.close()
github ResidentMario / geoplot / examples / plot_obesity.py View on Github external
import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt
import mapclassify as mc

# load the data
obesity_by_state = pd.read_csv(gplt.datasets.get_path('obesity_by_state'), sep='\t')
contiguous_usa = gpd.read_file(gplt.datasets.get_path('contiguous_usa'))
contiguous_usa['Obesity Rate'] = contiguous_usa['state'].map(
    lambda state: obesity_by_state.query("State == @state").iloc[0]['Percent']
)
scheme = mc.Quantiles(contiguous_usa['Obesity Rate'], k=5)


ax = gplt.cartogram(
    contiguous_usa,
    scale='Obesity Rate', limits=(0.75, 1),
    projection=gcrs.AlbersEqualArea(central_longitude=-98, central_latitude=39.5),
    hue='Obesity Rate', cmap='Reds', scheme=scheme,
    linewidth=0.5,
    legend=True, legend_kwargs={'loc': 'lower right'}, legend_var='hue',
    figsize=(8, 12)
)
gplt.polyplot(contiguous_usa, facecolor='lightgray', edgecolor='None', ax=ax)

plt.title("Adult Obesity Rate by State, 2013")
plt.savefig("obesity.png", bbox_inches='tight', pad_inches=0.1)
github ResidentMario / geoplot / docs / gallery / plot_obesity.py View on Github external
import pandas as pd
import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt

# load the data
obesity_by_state = pd.read_csv(gplt.datasets.get_path('obesity_by_state'), sep='\t')
contiguous_usa = gpd.read_file(gplt.datasets.get_path('contiguous_usa'))
contiguous_usa['Obesity Rate'] = contiguous_usa['state'].map(
    lambda state: obesity_by_state.query("State == @state").iloc[0]['Percent']
)


ax = gplt.cartogram(
    contiguous_usa,
    scale='Obesity Rate', limits=(0.75, 1),
    projection=gcrs.AlbersEqualArea(central_longitude=-98, central_latitude=39.5),
    hue='Obesity Rate', cmap='Reds', k=5,
    linewidth=0.5,
    legend=True, legend_kwargs={'loc': 'lower right'}, legend_var='hue',
    figsize=(12, 12)
)
gplt.polyplot(contiguous_usa, facecolor='lightgray', edgecolor='None', ax=ax)

plt.title("Adult Obesity Rate by State, 2013")
plt.savefig("obesity.png", bbox_inches='tight', pad_inches=0.1)
github geopandas / geopandas / examples / plotting_with_geoplot.py View on Github external
import mapclassify
gpd_per_person = world['gdp_md_est'] / world['pop_est']
scheme = mapclassify.Quantiles(gpd_per_person, k=5)

# Note: this code sample requires geoplot>=0.4.0.
geoplot.choropleth(
    world, hue=gpd_per_person, scheme=scheme,
    cmap='Greens', figsize=(8, 4)
)

###############################################################################
# If you want to use size as a visual variable, use a ``cartogram``. Here are
# population estimates for countries in Africa.

africa = world.query('continent == "Africa"')
ax = geoplot.cartogram(
    africa, scale='pop_est', limits=(0.2, 1),
    edgecolor='None', figsize=(7, 8)
)
geoplot.polyplot(africa, edgecolor='gray', ax=ax)

###############################################################################
# If we have data in the shape of points in space, we may generate a
# three-dimensional heatmap on it using ``kdeplot``.

ax = geoplot.kdeplot(
    collisions.head(1000), clip=boroughs.geometry,
    shade=True, cmap='Reds',
    projection=geoplot.crs.AlbersEqualArea())
geoplot.polyplot(boroughs, ax=ax, zorder=1)

###############################################################################