import quilt
from quilt.data.ResidentMario import geoplot_data
import geopandas as gpd

boroughs = gpd.read_file(geoplot_data.nyc_boroughs())
injurious_collisions = gpd.read_file(geoplot_data.nyc_injurious_collisions())

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

import geoplot as gplt
import matplotlib.pyplot as plt

f, axarr = plt.subplots(1, 2, figsize=(16, 8))

gplt.voronoi(injurious_collisions.head(1000), edgecolor='lightsteelblue', linewidth=0.5, ax=axarr[0])
gplt.polyplot(boroughs, linewidth=0.5, ax=axarr[0])

gplt.voronoi(injurious_collisions.head(1000), hue='NUMBER OF PERSONS INJURED', cmap='Reds',
             edgecolor='white', clip=boroughs.geometry,
             linewidth=0.5, categorical=True, ax=axarr[1])
gplt.polyplot(boroughs, linewidth=1, ax=axarr[1])

axarr[0].axis('off')
axarr[1].axis('off')

plt.suptitle("Injurious Car Crashes in New York City, 2016", fontsize=20, y=0.95)

plt.savefig("nyc-collisions-voronoi.png", bbox_inches='tight', pad_inches=0)
Exemplo n.º 2
0
pd.set_option('max_columns', 6)

# Load and display some example data.
# All of the examples in this notebook use the `quilt` package to do this.
from quilt.data.ResidentMario import geoplot_data

continental_cities = gpd.read_file(
    geoplot_data.usa_cities()).query('POP_2010 > 100000')
contiguous_usa = gpd.read_file(geoplot_data.contiguous_usa())
continental_cities.head()

import matplotlib.pyplot as plt

collisions = gpd.read_file(geoplot_data.nyc_collision_factors())
boroughs = gpd.read_file(geoplot_data.nyc_boroughs())
census_tracts = gpd.read_file(geoplot_data.ny_census_partial())
percent_white = census_tracts['WHITE'] / census_tracts['POP2000']
obesity = geoplot_data.obesity_by_state()
contiguous_usa = gpd.read_file(geoplot_data.contiguous_usa())
contiguous_usa['Obesity Rate'] = contiguous_usa['State'].map(
    lambda state: obesity.query("State == @state").iloc[0]['Percent'])
la_flights = gpd.read_file(geoplot_data.la_flights())
la_flights = la_flights.assign(start=la_flights.geometry.map(lambda mp: mp[0]),
                               end=la_flights.geometry.map(lambda mp: mp[1]))
collisions = gpd.read_file(geoplot_data.nyc_collision_factors())
boroughs = gpd.read_file(geoplot_data.nyc_boroughs())

ax = gplt.kdeplot(
    collisions,
    projection=gcrs.AlbersEqualArea(),