Choropleth maps

A choropleth map colours geographic regions (polygons) according to a data value. earthkit-plots supports choropleth maps from any GeoDataFrame — here we use ERA5 2-metre temperature averaged over NUTS regions.

[1]:
import earthkit.data as ekd

import earthkit.plots as ekp

nuts_mean_2t = ekd.from_source("sample", "era5-nuts-mean-2t.geojson").to_pandas()
[2]:
nuts_mean_2t
[2]:
id NUTS_ID LEVL_CODE CNTR_CODE NAME_LATN NUTS_NAME MOUNT_TYPE URBN_TYPE COAST_TYPE FID 2t geometry
0 DK DK 0 DK Danmark Danmark 0 0 0 DK 278.709224 MULTIPOLYGON (((15.1629 55.0937, 15.094 54.996...
1 RS RS 0 RS Serbia Srbija/Сpбија 0 0 0 RS 257.467299 POLYGON ((21.4792 45.193, 21.3585 44.8216, 22....
2 EE EE 0 EE Eesti Eesti 0 0 0 EE 275.762907 MULTIPOLYGON (((27.357 58.7871, 27.6449 57.981...
3 EL EL 0 EL Elláda Ελλάδα 0 0 0 EL 274.514026 MULTIPOLYGON (((28.0777 36.1182, 27.8606 35.92...
4 ES ES 0 ES España España 0 0 0 ES 273.998565 MULTIPOLYGON (((4.391 39.8617, 4.1907 39.7981,...
5 FI FI 0 FI Suomi/Finland Suomi/Finland 0 0 0 FI 273.595243 MULTIPOLYGON (((28.8967 69.0426, 28.4782 68.51...
6 FR FR 0 FR France France 0 0 0 FR 270.832357 MULTIPOLYGON (((55.8498 -21.1858, 55.7858 -21....
7 HR HR 0 HR Hrvatska Hrvatska 0 0 0 HR 262.673420 MULTIPOLYGON (((17.6515 45.8478, 17.9121 45.79...
8 HU HU 0 HU Magyarország Magyarország 0 0 0 HU 264.999617 POLYGON ((22.1211 48.3783, 22.1553 48.4034, 22...
9 IE IE 0 IE Éire/Ireland Éire/Ireland 0 0 0 IE 282.472782 POLYGON ((-7.1885 54.3377, -6.8642 54.3302, -6...
10 IS IS 0 IS Ísland Ísland 0 0 0 IS NaN POLYGON ((-22.1255 64.0406, -21.7569 64.3256, ...
11 IT IT 0 IT Italia Italia 0 0 0 IT 271.766854 MULTIPOLYGON (((12.2407 47.0692, 12.2117 46.89...
12 LI LI 0 LI Liechtenstein Liechtenstein 0 0 0 LI NaN POLYGON ((9.6206 47.1516, 9.6071 47.0608, 9.47...
13 LT LT 0 LT Lietuva Lietuva 0 0 0 LT 274.576225 POLYGON ((22.9205 56.3991, 23.1554 56.3288, 24...
14 LU LU 0 LU Luxembourg Luxembourg 0 0 0 LU 270.596191 POLYGON ((6.1377 50.13, 6.475 49.8213, 6.3801 ...
15 LV LV 0 LV Latvija Latvija 0 0 0 LV 275.123089 POLYGON ((27.6908 57.3706, 28.1546 56.1698, 27...
16 ME ME 0 ME Crna Gora Црна Гора 0 0 0 ME 262.123379 POLYGON ((20.0639 43.0068, 20.3529 42.8334, 20...
17 MK MK 0 MK Severna Makedonija Северна Македонија 0 0 0 MK 263.131301 POLYGON ((22.9683 41.5198, 22.9276 41.3385, 22...
18 MT MT 0 MT Malta Malta 0 0 0 MT 281.180176 MULTIPOLYGON (((14.6459 35.9333, 14.4334 35.71...
19 SE SE 0 SE Sverige Sverige 0 0 0 SE 276.116069 MULTIPOLYGON (((20.5486 69.06, 23.4078 68.023,...
20 SI SI 0 SI Slovenija Slovenija 0 0 0 SI 260.379829 POLYGON ((16.3708 46.7222, 16.5968 46.4759, 16...
21 SK SK 0 SK Slovensko Slovensko 0 0 0 SK 266.817063 POLYGON ((19.4674 49.6138, 19.8839 49.2042, 20...
22 TR TR 0 TR Türkiye Türkiye 0 0 0 TR 275.795532 MULTIPOLYGON (((35.5137 41.636, 35.9494 41.699...
23 UK UK 0 UK United Kingdom United Kingdom 0 0 0 UK 280.901408 MULTIPOLYGON (((-0.1102 51.5096, -0.0247 51.48...
24 NL NL 0 NL Nederland Nederland 0 0 0 NL 275.540895 MULTIPOLYGON (((7.2028 53.1133, 7.0927 52.8382...
25 PL PL 0 PL Polska Polska 0 0 0 PL 273.423917 POLYGON ((18.5417 54.5845, 18.95 54.3583, 19.6...
26 PT PT 0 PT Portugal Portugal 0 0 0 PT 276.422191 MULTIPOLYGON (((-8.199 42.1544, -8.1651 41.818...
27 RO RO 0 RO România România 0 0 0 RO 257.307949 POLYGON ((27.3912 47.5894, 28.1138 46.8384, 28...
28 AL AL 0 AL Shqipëria Shqipëria 0 0 0 AL 267.028035 POLYGON ((20.0763 42.5558, 20.2649 42.3929, 20...
29 AT AT 0 AT Österreich Österreich 0 0 0 AT 267.111113 POLYGON ((16.9403 48.6172, 16.9498 48.5358, 16...
30 BE BE 0 BE Belgique/België Belgique/België 0 0 0 BE 272.989683 POLYGON ((5.5663 51.2208, 5.7983 51.0599, 5.76...
31 BG BG 0 BG Bulgaria България 0 0 0 BG 261.698826 POLYGON ((22.9664 44.0983, 22.9972 43.8079, 23...
32 CH CH 0 CH Schweiz/Suisse/Svizzera Schweiz/Suisse/Svizzera 0 0 0 CH 264.816124 POLYGON ((9.1822 47.6559, 9.4956 47.5515, 9.55...
33 CY CY 0 CY Kýpros Κύπρος 0 0 0 CY 286.122493 POLYGON ((33.6251 34.8511, 32.9417 34.6418, 32...
34 CZ CZ 0 CZ Česko Česko 0 0 0 CZ 270.750695 POLYGON ((14.4912 51.0435, 14.6188 50.8578, 14...
35 DE DE 0 DE Deutschland Deutschland 0 0 0 DE 274.469295 MULTIPOLYGON (((9.1131 54.8736, 9.2736 54.8117...
36 NO NO 0 NO Norge Norge 0 0 0 NO 272.673913 MULTIPOLYGON (((28.8967 69.0426, 29.1537 69.58...

Plotting the raw GeoDataFrame

You can pass a GeoDataFrame directly to ekp.geo.choropleth. When no value column is specified, earthkit-plots uses a categorical colour scheme so you can immediately see the shape and coverage of the regions.

[3]:
ekp.geo.choropleth(nuts_mean_2t)
[3]:
<earthkit.plots.components.maps.Map at 0x113b7f9d0>
../../../_images/examples_examples_misc_choropleth_4_1.png

Colouring by a data column

Pass the z argument to select the column whose values drive the colour scale. Here we colour each NUTS region by its mean 2-metre temperature.

[4]:
ekp.geo.choropleth(nuts_mean_2t, z="2t")
[4]:
<earthkit.plots.components.maps.Map at 0x127bed750>
../../../_images/examples_examples_misc_choropleth_6_1.png

Adding a domain and data labels

ekp.geo.choropleth accepts the same domain argument as other earthkit-plots functions. You can also overlay text labels on each region using a format string that references column names in curly braces.

[5]:
ekp.geo.choropleth(nuts_mean_2t, z="2t", domain="Europe", labels="{2t:.1f}")
[5]:
<earthkit.plots.components.maps.Map at 0x107bbc490>
../../../_images/examples_examples_misc_choropleth_8_1.png

Reusable styles and metadata

As with other plot types you can pass a Style object to control colour levels and the colour map, and a metadata dict to provide unit and long-name information for unit conversion plus title and label formatting.

[6]:
style = ekp.styles.Style(
    levels=range(-10, 11),
    cmap="RdBu_r",
    units="celsius",
)

ekp.geo.choropleth(
    nuts_mean_2t,
    domain="Europe",
    z="2t",
    labels="{2t:.1f}{units}",
    metadata={"units": "K", "long_name": "2m temperature"},
    style=style,
).show()
../../../_images/examples_examples_misc_choropleth_10_0.png
[6]:
<earthkit.plots.components.figures.Figure at 0x113b73c50>