.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_nyc_collision_factors.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_collision_factors.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 9-50 .. image:: /gallery/images/sphx_glr_plot_nyc_collision_factors_001.png :alt: Failure to Yield Right-of-Way Crashes, 2016, Loss of Consciousness Crashes, 2016 :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'rocket' which already exists. mpl_cm.register_cmap(_name, _cmap) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'rocket_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'mako' which already exists. mpl_cm.register_cmap(_name, _cmap) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'mako_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'icefire' which already exists. mpl_cm.register_cmap(_name, _cmap) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'icefire_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'vlag' which already exists. mpl_cm.register_cmap(_name, _cmap) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'vlag_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'flare' which already exists. mpl_cm.register_cmap(_name, _cmap) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'flare_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1582: UserWarning: Trying to register the cmap 'crest' which already exists. mpl_cm.register_cmap(_name, _cmap) /Users/alekseybilogur/opt/miniconda3/envs/geoplot-dev/lib/python3.8/site-packages/seaborn/cm.py:1583: UserWarning: Trying to register the cmap 'crest_r' which already exists. mpl_cm.register_cmap(_name + "_r", _cmap_r) Text(0.5, 1.0, 'Loss of Consciousness Crashes, 2016') | .. code-block:: default 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, thresh=0.05, clip=nyc_boroughs.geometry, ax=ax1 ) gplt.polyplot(nyc_boroughs, zorder=1, ax=ax1) ax1.set_title("Failure to Yield Right-of-Way Crashes, 2016") gplt.kdeplot( nyc_collision_factors[ nyc_collision_factors['CONTRIBUTING FACTOR VEHICLE 1'] == "Lost Consciousness" ], cmap='Reds', projection=proj, shade=True, thresh=0.05, clip=nyc_boroughs.geometry, ax=ax2 ) gplt.polyplot(nyc_boroughs, zorder=1, ax=ax2) ax2.set_title("Loss of Consciousness Crashes, 2016") .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 8.911 seconds) .. _sphx_glr_download_gallery_plot_nyc_collision_factors.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_collision_factors.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_nyc_collision_factors.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_