.. currentmodule:: geomappy.. note:: This tutorial was generated from an IPython notebook that can be downloaded `here <../../../source/notebooks/geopandas_integration.ipynb>`_. .. _geopandas_integration: Integration of Geomappy into GeoPandas ====================================== .. code:: python import geopandas as gpd import matplotlib.pyplot as plt import geomappy as mp import os .. code:: python os.chdir("../../../") Loading data on river plastic mobilisation when flood events happen (Roebroek et al., 2021). .. code:: python df1 = gpd.read_file("data/countries/plastic_mobilisation.shp") df1.columns .. parsed-literal:: Index(['featurecla', 'scalerank', 'LABELRANK', 'SOVEREIGNT', 'SOV_A3', 'ADM0_DIF', 'LEVEL', 'TYPE', 'ADMIN', 'ADM0_A3', ... 'NAME_ZH', 'e_1', 'e_10', 'e_20', 'e_50', 'e_100', 'e_200', 'e_500', 'jump', 'geometry'], dtype='object', length=103) Loading data on riverbank plastic observations in the Netherlands (Van Emmerik et al., 2020) .. code:: python df2 = gpd.read_file("data/processed_data_SDN/df_locations.geojson") df2.columns .. parsed-literal:: Index(['Gebiedscode', 'river', 'x_maas', 'x_waal', 'geometry'], dtype='object') Outline on a world map ---------------------- The first file covers the world, while the second file covers the Netherlands. Both have different projections. Geomappy allows to visualise it like this: .. code:: python df1.plot_world() df2.plot_world() plt.show() .. image:: geopandas_integration_files/geopandas_integration_9_0.png .. image:: geopandas_integration_files/geopandas_integration_9_1.png Plotting the data ----------------- The geomappy plotting functionality (``plot_shapes``) is directly integrated into geopandas by loading geomappy. This results in the same figure as seen before: .. code:: python df1.plot_shapes() plt.show() .. image:: geopandas_integration_files/geopandas_integration_12_0.png .. code:: python df2.plot_shapes() plt.show() .. image:: geopandas_integration_files/geopandas_integration_13_0.png Again all plotting functionaly of ``plot_shapes`` is available. This is shown here by reproducing the same map as in the tutorial on choropleth continues shapes tutorial .. code:: python im, cbar = df1.plot_shapes( values='e_10', cmap="Reds", bins=[0,100,1000,10000,100000,1000000, 10000000, 100000000] ) cbar.ax.set_yticklabels([0, "E2", "E3", "E4", "E5", "E6", "E7", "E8"], fontsize=8) cbar.set_label("Plastic mobilisation", labelpad=15, rotation=270, fontsize=8) plt.show() .. image:: geopandas_integration_files/geopandas_integration_15_0.png