Introduction to filled contours

Filled contour plots shade the regions between contour levels with colour, making it easy to see the overall spatial pattern of a field at a glance.

This notebook introduces the two main ways to draw filled contours in earthkit-plots:

  • ekp.geo.contourf – the high-level, single-call API

  • Map.contourf – the lower-level API for full control and layering

[1]:
import earthkit.data as ekd

import earthkit.plots as ekp

data = ekd.from_source("sample", "era5-2t-msl-1985122512.grib").to_fieldlist()
pressure = data.sel({"parameter.variable": "msl"})
temperature = data.sel({"parameter.variable": "2t"})

High-level API: ekp.geo.contourf

The simplest entry point. By default it uses the plasma colour map and picks sensible levels automatically.

[2]:
ekp.geo.contourf(temperature, units="celsius", domain="Europe")
[2]:
<earthkit.plots.components.maps.Map at 0x1393cda90>
../../../_images/examples_examples_contourf_contourf-introduction_3_1.png

Automatic styles with style="auto"

For well-known variables earthkit-plots can select a pre-defined style automatically.

[3]:
ekp.geo.contourf(temperature, units="celsius", style="auto", domain="Europe")
[3]:
<earthkit.plots.components.maps.Map at 0x13bfa0fd0>
../../../_images/examples_examples_contourf_contourf-introduction_5_1.png

ekp.geo.plot does the same thing but also chooses the method (filled contour, contour lines, etc.) automatically:

[4]:
ekp.geo.plot(temperature, units="celsius")
[4]:
<earthkit.plots.components.maps.Map at 0x139429010>
../../../_images/examples_examples_contourf_contourf-introduction_7_1.png

Lower-level API: Map.contourf

Create the map first, then add layers. This makes it straightforward to combine filled contours with other plot types.

[5]:
chart = ekp.Map(domain="Europe")
chart.contourf(temperature, units="celsius")
chart.legend()
chart.land()
chart.coastlines()
chart.title()
chart.show()
../../../_images/examples_examples_contourf_contourf-introduction_9_0.png

Choosing a different colour map

Pass any named matplotlib colour map via colors:

[6]:
chart = ekp.Map(domain="Europe")
chart.contourf(temperature, units="celsius", colors="RdYlBu_r")
chart.legend()
chart.land()
chart.coastlines()
chart.title()
chart.show()
../../../_images/examples_examples_contourf_contourf-introduction_11_0.png

What’s next?

The next notebook covers how to control colour levels and build reusable styles for filled contour plots.