.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_15_stdmean.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_15_stdmean.py: Standard-deviation choropleth (double gamme) ============================================ The *StdMean* method places its class breaks at standard-deviation steps either side of the mean, with a central class straddling it. It is a *diverging* classification, so it pairs with a *double gamme* (diverging) palette: one colour ramp below the mean and one above, meeting at a neutral centre. Only odd class counts make that symmetry work, so StdMean accepts **5 or 7** classes; any other count snaps to the nearest valid one with a warning. ``reverse=True`` flips the double ramp (*gamme inversee*) without moving the neutral centre: handy when high values should read "cool" rather than "warm". Hover a department to read its value. .. GENERATED FROM PYTHON SOURCE LINES 19-61 .. raw:: html Source: Sante publique France (ODISSE) Deaths / 100,000 inhab. (std-dev classes) 25 35 39 43 52 56 60 71 Mortality from heart failure Standard-deviation classes around the mean .. code-block:: Python from pathlib import Path import pandas as pd from mappyng import Map, ChoroplethLayer from mappyng.data import load_france_departments # Metropolitan France only (two-character department codes). deps = load_france_departments().to_crs(2154) deps = deps[deps["COD_GEO"].str.len() == 2] df = pd.read_csv(Path("data") / "cardio_mortalite_dep.csv", dtype={"code_dep": str}) deps = deps.merge(df, left_on="COD_GEO", right_on="code_dep", how="left") m = Map(deps, width=820, height="auto", border_radius=0) # StdMean with 7 classes and a diverging "double gamme" (RdBu). Use # reverse=True to invert it: departments above the mean read blue, below # the mean read red, with the neutral class kept in the centre. m.add(ChoroplethLayer( deps, column="taux_mortalite", cmap="RdBu", method="StdMean", num_classes=7, reverse=True, stroke_width=0.2, legend={"title": "Deaths / 100,000 inhab. (std-dev classes)", "orientation": "horizontal", "decimals": 0, "nodata_label": "No data"}, )) m.title("Mortality from heart failure", subtitle="Standard-deviation classes around the mean") m.source("Source: Sante publique France (ODISSE)") # Hover tooltips. The gallery embeds an interactive SVG from this dict; the # same call also yields a standalone HTML file. TOOLTIP = {"columns": ["LIB_GEO", "taux_mortalite"], "aliases": {"LIB_GEO": "Department", "taux_mortalite": "Rate"}} interactive = m.to_interactive(**TOOLTIP) # interactive.save("stdmean.html") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.131 seconds) .. _sphx_glr_download_gallery_plot_15_stdmean.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_15_stdmean.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_15_stdmean.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_15_stdmean.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_