.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_nyc_parking_tickets.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_plot_nyc_parking_tickets.py: Choropleth of parking tickets issued to state by precinct in NYC ================================================================ This example plots a subset of parking tickets issued to drivers in New York City. Specifically, it plots the subset of tickets issued in the city which are more common than average for that state than the average. This difference between "expected tickets issued" and "actual tickets issued" is interesting because it shows which areas visitors driving into the city from a specific state are more likely visit than their peers from other states. Observations that can be made based on this plot include: * Only New Yorkers visit Staten Island. * Drivers from New Jersey, many of whom likely work in New York City, bias towards Manhattan. * Drivers from Pennsylvania and Connecticut bias towards the borough closest to their state: 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" `_. .. GENERATED FROM PYTHON SOURCE LINES 22-63 .. image:: /gallery/images/sphx_glr_plot_nyc_parking_tickets_001.png :alt: Parking Tickets Issued to State by Precinct, 2016, New York (n=6,679,268), New Jersey (n=854,647), Pennsylvania (n=215,065), Connecticut (n=126,661) :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Text(0.5, 1.0, 'Connecticut (n=126,661)') | .. code-block:: default 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, 13), subplot_kw={'projection': proj}) plt.suptitle('Parking Tickets Issued to State by Precinct, 2016', fontsize=16) plt.subplots_adjust(top=0.95) plot_state_to_ax('ny', axarr[0][0]) axarr[0][0].set_title('New York (n=6,679,268)') plot_state_to_ax('nj', axarr[0][1]) axarr[0][1].set_title('New Jersey (n=854,647)') plot_state_to_ax('pa', axarr[1][0]) axarr[1][0].set_title('Pennsylvania (n=215,065)') plot_state_to_ax('ct', axarr[1][1]) axarr[1][1].set_title('Connecticut (n=126,661)') .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 4.402 seconds) .. _sphx_glr_download_gallery_plot_nyc_parking_tickets.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_nyc_parking_tickets.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_nyc_parking_tickets.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_