.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_14_acp.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_14_acp.py: Factor maps of a principal component analysis ============================================= A choropleth of the first factor of a principal component analysis on 42 African countries (demographic, social and economic indicators). The axis is diverging and centred on zero. :class:`~mappyng.FactorLegend` adds what such a map needs: the factor and its share of variance, an interpretation text at each pole, a no-data entry and a methodology note. By default the legend sits below the map. The same map is shown twice: a vertical legend, then a horizontal one. The legend reads high to low: the positive pole (mostly agricultural, young, high fertility) and the negative pole (high GNP and GDP), each marked by an arrow. .. GENERATED FROM PYTHON SOURCE LINES 16-57 .. raw:: html Source: ENSG L1 cartostat, TD3 (African country indicators) Coordinates on the first factor 58.8% of total variance Mostly agricultural, under 15, high fertility 4.20 2.28 1.24 0.24 -2.01 -6.52 High GNP and GDP No data Standardised PCA on 42 African countries, late 20th century. African development First factor of a standardised PCA .. raw:: html Source: ENSG L1 cartostat, TD3 (African country indicators) Coordinates on the first factor 58.8% of total variance - High GNP and GDP Mostly agricultural, under 15, high fertility + -6.52 -2.01 0.24 1.24 2.28 4.20 No data Standardised PCA on 42 African countries, late 20th century. African development First factor of a standardised PCA .. code-block:: Python from pathlib import Path import geopandas as gpd from mappyng import Map, ChoroplethLayer, FactorLegend countries = gpd.read_file(Path("data") / "afrique_acp_cp1.geojson") POLES = dict( title="Coordinates on the first factor", variance=0.588, pole_high="Mostly agricultural, under 15, high fertility", pole_low="High GNP and GDP", note="Standardised PCA on 42 African countries, late 20th century.", nodata_label="No data", decimals=2, ) def _factor_map(orientation): m = Map(countries, width=720, height="auto", facecolor="#ffffff") m.add(ChoroplethLayer( countries, column="cp1", cmap="RdYlGn", method="Quantiles", num_classes=5, stroke_width=0.2, legend=FactorLegend(orientation=orientation, **POLES))) m.title("African development", subtitle="First factor of a standardised PCA") m.source("Source: ENSG L1 cartostat, TD3 (African country indicators)") return m # Vertical legend, then horizontal: both render on this page. vertical = _factor_map("vertical") horizontal = _factor_map("horizontal") # Hover tooltips. The gallery embeds an interactive SVG from this dict; the # same call also yields a standalone HTML file. TOOLTIP = {"columns": ["nom", "cp1"], "aliases": {"nom": "Country", "cp1": "Factor 1"}} interactive = vertical.to_interactive(**TOOLTIP) # interactive.save("acp.html") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.220 seconds) .. _sphx_glr_download_gallery_plot_14_acp.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_14_acp.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_14_acp.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_14_acp.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_