Plotting the Warming StripesΒΆ

In this recipe, we will plot the Warming Stripes (Climate Stripes) created by Professor Ed Hawkins at NCAS, University of Reading. Here we will use the ensemble mean of the HadCRUT. analysis gridded data for the same.

  1. Import cf-python and matplotlib.pyplot:

import matplotlib.pyplot as plt

import cf
  1. Read the field constructs:

temperature_data =
Field: long_name=blended air_temperature_anomaly over land with sea_water_temperature_anomaly (ncvar%tas_mean)
Data            : long_name=blended air_temperature_anomaly over land with sea_water_temperature_anomaly(time(2074), latitude(36), longitude(72)) K
Cell methods    : area: mean (interval: 5.0 degrees_north) time(2074): mean (interval: 1 month) realization(1): mean
Dimension coords: time(2074) = [1850-01-16 12:00:00, ..., 2022-10-16 12:00:00] gregorian
                : latitude(36) = [-87.5, ..., 87.5] degrees_north
                : longitude(72) = [-177.5, ..., 177.5] degrees_east
                : realization(1) = [100] 1

3. Calculate the annual mean temperature anomalies. The 'weights=True' argument is used to take the varying lengths of months into account which ensures that the calculated mean is more accurate:

annual_temperature = temperature_data.collapse(
    "T: mean", weights=True, group=cf.Y()
  1. Select the data from 1850 to 2022:

  1. Calculate the global average temperature for each year:

  1. Get the global average temperature and squeeze it to remove the size 1 axis:

7. Create a normalization function that maps the interval from the minimum to the maximum temperature to the interval [0, 1] for colouring:

  1. Set the colormap instance:

cmap = plt.get_cmap("RdBu_r")

9. Create the figure and the axes for the global plot. Loop over the selected years, plot a colored vertical stripe for each and remove the axes:

fig_global, ax_global = plt.subplots(figsize=(10, 2))

for i in range(global_avg_temp.shape[0]):
        xmin=i - 0.5, xmax=i + 0.5, color=cmap(norm_global(global_avg_temp[i]))

plot 11 recipe

10. For the regional warming stripes, steps 5 to 9 are repeated for the specific region. Here, we define the bounding box for UK by subspacing over a domain spanning 49.9 to 59.4 degrees north and -10.5 to 1.8 degrees east:

fig_uk, ax_uk = plt.subplots(figsize=(10, 2))

for i in range(uk_avg_temp.shape[0]):
        xmin=i - 0.5, xmax=i + 0.5, color=cmap(norm_uk(uk_avg_temp[i]))

plot 11 recipe

Total running time of the script: ( 0 minutes 21.115 seconds)

Gallery generated by Sphinx-Gallery