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 APIMap.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>
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>
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>
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()
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()
What’s next?¶
The next notebook covers how to control colour levels and build reusable styles for filled contour plots.