How to use the geoplot.datasets 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 / docs / examples / nyc-collisions-voronoi.py View on Github external
import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt

# load the data
nyc_boroughs = gpd.read_file(gplt.datasets.get_path('nyc_boroughs'))
nyc_injurious_collisions = gpd.read_file(gplt.datasets.get_path('nyc_injurious_collisions'))

# A plot type using Voronoi tessellation: https://en.wikipedia.org/wiki/Voronoi_diagram

proj = gcrs.AlbersEqualArea(central_latitude=40.7128, central_longitude=-74.0059)
f, axarr = plt.subplots(
    1, 2, figsize=(16, 8), subplot_kw={'projection': proj}
)
axarr[0].axis('off')
axarr[1].axis('off')
gplt.voronoi(
    nyc_injurious_collisions.head(1000),
    edgecolor='lightsteelblue', linewidth=0.5, ax=axarr[0],
)
gplt.polyplot(nyc_boroughs, linewidth=0.5, ax=axarr[0])
gplt.voronoi(
    nyc_injurious_collisions.head(1000),
github ResidentMario / geoplot / examples / plot_largest_cities_usa.py View on Github external
"""
Pointplot of US cities by population
====================================

This example, taken from the User Guide, plots cities in the contiguous United States by their
population. It demonstrates some of the range of styling options available in ``geoplot``.
"""


import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt
import mapclassify as mc

continental_usa_cities = gpd.read_file(gplt.datasets.get_path('usa_cities'))
continental_usa_cities = continental_usa_cities.query('STATE not in ["AK", "HI", "PR"]')
contiguous_usa = gpd.read_file(gplt.datasets.get_path('contiguous_usa'))
scheme = mc.Quantiles(continental_usa_cities['POP_2010'], k=5)

ax = gplt.polyplot(
    contiguous_usa, 
    zorder=-1,
    linewidth=1,
    projection=gcrs.AlbersEqualArea(),
    edgecolor='white',
    facecolor='lightgray',
    figsize=(8, 12)
)
gplt.pointplot(
    continental_usa_cities, 
    scale='POP_2010',
github ResidentMario / geoplot / _downloads / 3dcded7153c2dd631cf592a948363b12 / plot_nyc_parking_tickets.py View on Github external
The Bronx for Connecticut, Brooklyn for Pennsylvania.

This example was inspired by the blog post `"Californians love Brooklyn, New Jerseyans love
Midtown: Mapping NYC’s Visitors Through Parking Tickets"
`_.
"""


import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt

# load the data
nyc_boroughs = gpd.read_file(gplt.datasets.get_path('nyc_boroughs'))
tickets = gpd.read_file(gplt.datasets.get_path('nyc_parking_tickets'))

proj = gcrs.AlbersEqualArea(central_latitude=40.7128, central_longitude=-74.0059)
def plot_state_to_ax(state, ax):
    gplt.choropleth(
        tickets.set_index('id').loc[:, [state, 'geometry']],
        hue=state, cmap='Blues',
        linewidth=0.0, ax=ax
    )
    gplt.polyplot(
        nyc_boroughs, edgecolor='black', linewidth=0.5, ax=ax
    )

f, axarr = plt.subplots(2, 2, figsize=(12, 12), subplot_kw={'projection': proj})

plt.suptitle('Parking Tickets Issued to State by Precinct, 2016', fontsize=16)
plt.subplots_adjust(top=0.95)
github ResidentMario / geoplot / examples / plot_nyc_collision_factors.py View on Github external
"""
KDEPlot of two NYC traffic accident contributing factors
========================================================

This example shows traffic accident densities for two common contributing factors: loss of
consciousness and failure to yield right-of-way. These factors have very different geospatial
distributions: loss of consciousness crashes are more localized to Manhattan.
"""


import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt

nyc_boroughs = gpd.read_file(gplt.datasets.get_path('nyc_boroughs'))
nyc_collision_factors = gpd.read_file(gplt.datasets.get_path('nyc_collision_factors'))


proj = gcrs.AlbersEqualArea(central_latitude=40.7128, central_longitude=-74.0059)
fig = plt.figure(figsize=(10,5))
ax1 = plt.subplot(121, projection=proj)
ax2 = plt.subplot(122, projection=proj)

gplt.kdeplot(
    nyc_collision_factors[
        nyc_collision_factors['CONTRIBUTING FACTOR VEHICLE 1'] == "Failure to Yield Right-of-Way"
    ],
    cmap='Reds',
    projection=proj,
    shade=True, shade_lowest=False, 
    clip=nyc_boroughs.geometry,
github ResidentMario / geoplot / docs / examples / boston-airbnb-aggplot.py View on Github external
import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import numpy as np
import matplotlib.pyplot as plt

# load the data
boston_zip_codes = gpd.read_file(gplt.datasets.get_path('boston_zip_codes'))
boston_zip_codes = boston_zip_codes.assign(id=boston_zip_codes.id.astype(float)).set_index('id')
boston_airbnb_listings = gpd.read_file(gplt.datasets.get_path('boston_airbnb_listings'))

ax = gplt.polyplot(
    boston_zip_codes, 
    projection=gcrs.AlbersEqualArea(),
    facecolor='lightgray',
    edgecolor='gray',
    linewidth=0
)
gplt.aggplot(
    boston_airbnb_listings,
    hue='price',
    by='zipcode',
    geometry=boston_zip_codes,
    agg=np.median,
    ax=ax,
    linewidth=0
github ResidentMario / geoplot / docs / gallery / plot_nyc_collisions_map.py View on Github external
Pointplot of NYC fatal and injurious traffic collisions
=======================================================

The example ``pointplot`` of fatal (>1 fatality) and injurious (>1 injury requiring
a hospital visit) collisions demonstrates the difference in volume between the two types of
accident outcomes: injuries are much, much more common than fatalities.
"""


import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt

# load the data
nyc_boroughs = gpd.read_file(gplt.datasets.get_path('nyc_boroughs'))
nyc_fatal_collisions = gpd.read_file(gplt.datasets.get_path('nyc_fatal_collisions'))
nyc_injurious_collisions = gpd.read_file(gplt.datasets.get_path('nyc_injurious_collisions'))


fig = plt.figure(figsize=(10,5))
proj = projection=gcrs.AlbersEqualArea(central_latitude=40.7128, central_longitude=-74.0059)
ax1 = plt.subplot(121, projection=proj)
ax2 = plt.subplot(122, projection=proj)

ax1 = gplt.pointplot(
    nyc_fatal_collisions, projection=proj,
    hue='BOROUGH', cmap='Set1',
    edgecolor='white', linewidth=0.5,
    scale='NUMBER OF PERSONS KILLED', limits=(8, 24),
    legend=True, legend_var='scale',
    legend_kwargs={'loc': 'upper left', 'markeredgecolor': 'black'},
github ResidentMario / geoplot / examples / plot_nyc_collision_factors.py View on Github external
KDEPlot of two NYC traffic accident contributing factors
========================================================

This example shows traffic accident densities for two common contributing factors: loss of
consciousness and failure to yield right-of-way. These factors have very different geospatial
distributions: loss of consciousness crashes are more localized to Manhattan.
"""


import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt

nyc_boroughs = gpd.read_file(gplt.datasets.get_path('nyc_boroughs'))
nyc_collision_factors = gpd.read_file(gplt.datasets.get_path('nyc_collision_factors'))


proj = gcrs.AlbersEqualArea(central_latitude=40.7128, central_longitude=-74.0059)
fig = plt.figure(figsize=(10,5))
ax1 = plt.subplot(121, projection=proj)
ax2 = plt.subplot(122, projection=proj)

gplt.kdeplot(
    nyc_collision_factors[
        nyc_collision_factors['CONTRIBUTING FACTOR VEHICLE 1'] == "Failure to Yield Right-of-Way"
    ],
    cmap='Reds',
    projection=proj,
    shade=True, shade_lowest=False, 
    clip=nyc_boroughs.geometry,
    ax=ax1
github geopandas / geopandas / examples / plotting_with_geoplot.py View on Github external
library refer to `its documentation
`_.

First we'll load in the data using GeoPandas.
"""
import geopandas
import geoplot

world = geopandas.read_file(
    geopandas.datasets.get_path('naturalearth_lowres')
)
boroughs = geopandas.read_file(
    geoplot.datasets.get_path('nyc_boroughs')
)
collisions = geopandas.read_file(
    geoplot.datasets.get_path('nyc_injurious_collisions')
)

###############################################################################
# Plotting with Geoplot
# =====================
#
# We start out by replicating the basic GeoPandas world plot using Geoplot.
geoplot.polyplot(world, figsize=(8, 4))

###############################################################################
# Geoplot can re-project data into any of the map projections provided by
# CartoPy (see the list
# `here `_).

# use the Orthographic map projection (e.g. a world globe)
ax = geoplot.polyplot(
github ResidentMario / geoplot / docs / gallery / plot_usa_city_elevations.py View on Github external
In our demonstratory case the data is linear and not logorithmic in shape, so this doesn't come
out too well, but in other cases using the logorithm is the way to go.

The last demo shows a power scale. This is useful for data that follows a power law distribution
of some kind. Again, this doesn't work too well in our case.
"""

import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import numpy as np
import matplotlib.pyplot as plt

continental_usa_cities = gpd.read_file(gplt.datasets.get_path('usa_cities'))
continental_usa_cities = continental_usa_cities.query('STATE not in ["AK", "HI", "PR"]')
contiguous_usa = gpd.read_file(gplt.datasets.get_path('contiguous_usa'))


proj = gcrs.AlbersEqualArea(central_longitude=-98, central_latitude=39.5)
f, axarr = plt.subplots(2, 2, figsize=(12, 8), subplot_kw={'projection': proj})

polyplot_kwargs = {'facecolor': (0.9, 0.9, 0.9), 'linewidth': 0}
pointplot_kwargs = {
    'scale': 'ELEV_IN_FT', 'edgecolor': 'white', 'linewidth': 0.5, 'color': 'black'
}


gplt.polyplot(contiguous_usa.geometry, ax=axarr[0][0], **polyplot_kwargs)
gplt.pointplot(
    continental_usa_cities.query("POP_2010 > 10000"),
    ax=axarr[0][0], limits=(0.1, 10), **pointplot_kwargs
)
github geopandas / geopandas / examples / plotting_with_geoplot.py View on Github external
GeoPandas input.

This example is a brief tour of the `geoplot` API. For more details on the
library refer to `its documentation
`_.

First we'll load in the data using GeoPandas.
"""
import geopandas
import geoplot

world = geopandas.read_file(
    geopandas.datasets.get_path('naturalearth_lowres')
)
boroughs = geopandas.read_file(
    geoplot.datasets.get_path('nyc_boroughs')
)
collisions = geopandas.read_file(
    geoplot.datasets.get_path('nyc_injurious_collisions')
)

###############################################################################
# Plotting with Geoplot
# =====================
#
# We start out by replicating the basic GeoPandas world plot using Geoplot.
geoplot.polyplot(world, figsize=(8, 4))

###############################################################################
# Geoplot can re-project data into any of the map projections provided by
# CartoPy (see the list
# `here `_).