.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_17_detail.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_plot_17_detail.py: Finer geometry in a zoom window =============================== A map is often drawn from a *generalised* (simplified) layer, which keeps the file light but looks coarse once a dense area is magnified in a zoom window or an inset. ``detail`` lets a layer draw its zoom and inset views from a finer layer of the same areas, **keeping the layer's symbology**: the classes and colours are computed once, from the layer's own data, then carried to the finer outlines through a join key (``detail_join``). Here the coarse level is made by simplifying the departments (in practice you would load two generalisation levels of your own data). Both maps below zoom on Paris and its inner ring; only the second one passes ``detail``. Every department keeps the colour it has on the main map. Data: mortality from heart failure, rate per 100,000 inhabitants (Sante publique France, ODISSE). .. GENERATED FROM PYTHON SOURCE LINES 20-66 .. raw:: html Deaths / 100,000 25 42 46 50 53 71 No data Zoom from the generalised layer .. raw:: html Deaths / 100,000 25 42 46 50 53 71 No data Zoom from the finer layer .. code-block:: Python from pathlib import Path import pandas as pd import mappyng as mp from mappyng.data import load_france_departments fine = load_france_departments().to_crs(2154) df = pd.read_csv(Path("data") / "cardio_mortalite_dep.csv", dtype={"code_dep": str}) fine = fine.merge(df, left_on="COD_GEO", right_on="code_dep", how="left") # The coarse level: same departments, outlines simplified to 15 km. coarse = fine.copy() coarse["geometry"] = coarse.geometry.simplify(15000) BBOX_METRO = [90000, 6040000, 1280000, 7150000] PARIS = [500000, 6740000, 780000, 6940000] def build(detail=None): """The map; ``detail`` is the finer layer, or None for the plain zoom.""" return ( mp.Map(coarse, bbox=BBOX_METRO, width=800, height=800, facecolor="#dce6f0") + mp.Basemap(detail=detail) + mp.Choropleth( coarse, column="taux_mortalite", cmap="Reds", method="Quantiles", num_classes=5, stroke_width=0.15, legend=mp.Legend("Deaths / 100,000", orientation="horizontal", decimals=0, swatch_width=18, fontsize=7, label_rotation=0, nodata_label="No data"), on_zoom=True, detail=detail, # finer outlines for the zoom ... detail_join="COD_GEO", # ... joined on this column, in both layers ) + mp.Zoom(PARIS, x=520, y=90, width=250, height=250, border_radius=8) ) # Without ``detail``: the zoom is drawn from the coarse outlines. m_coarse = build() + mp.Title("Zoom from the generalised layer") # With ``detail``: finer outlines in the zoom, same colours. m_detail = build(detail=fine) + mp.Title("Zoom from the finer layer") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.245 seconds) .. _sphx_glr_download_gallery_plot_17_detail.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_17_detail.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_17_detail.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_17_detail.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_